Home
Classrooms
Courses
About Us
Resources
Members
More
E6.4 on page 295
import java.util.Scanner;
class stuff {
public static void main(String[] args) {
Scanner Riley = new Scanner(System.in);
System.out.println("Please enter a string:");
String s = Riley.nextLine();
String S = "";
for (int i=1; i<=s.length(); i++)
if (s.substring(i-1,i).toUpperCase().equals(s.substring(i-1,i))) {
S = S + s.substring(i-1,i);
}
System.out.println(S);
String t = Riley.nextLine();
String T = "";
for (int i=1; i<=t.length()-1; i+=2) {
T = T + t.substring(i,i+1);
System.out.println(T);
String u = Riley.nextLine();
for (int i=0; i<=u.length()-1; i++) {
switch (u.substring(i,i+1)) {
case "a": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "e": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "i": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "o": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "u": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "A": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "E": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "I": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "O": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "U": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
default: break;
System.out.println(u);
String v = Riley.nextLine();
int V = 0;
for (int i=0; i<=v.length()-1; i++) {
switch (v.substring(i,i+1)) {
case "a": V++; break;
case "e": V++; break;
case "i": V++; break;
case "o": V++; break;
case "u": V++; break;
case "A": V++; break;
case "E": V++; break;
case "I": V++; break;
case "O": V++; break;
case "U": V++; break;
System.out.println("The number of vowels in your string is " + V);
String w = Riley.nextLine();
for (int i=0; i<=w.length()-1; i++) {
switch (w.substring(i,i+1)) {
case "a": System.out.println("The posistion of letter a is " + (i+1)); break;
case "e": System.out.println("The posistion of letter e is " + (i+1)); break;
case "i": System.out.println("The posistion of letter i is " + (i+1)); break;
case "o": System.out.println("The posistion of letter o is " + (i+1)); break;
case "u": System.out.println("The posistion of letter u is " + (i+1)); break;
case "A": System.out.println("The posistion of letter A is " + (i+1)); break;
case "E": System.out.println("The posistion of letter E is " + (i+1)); break;
case "I": System.out.println("The posistion of letter I is " + (i+1)); break;
case "O": System.out.println("The posistion of letter O is " + (i+1)); break;
case "U": System.out.println("The posistion of letter U is " + (i+1)); break;
import java.util.Scanner;
class stuff {
public static void main(String[] args) {
Scanner Riley = new Scanner(System.in);
System.out.println("Please enter a string:");
String s = Riley.nextLine();
String S = "";
for (int i=1; i<=s.length(); i++)
if (s.substring(i-1,i).toUpperCase().equals(s.substring(i-1,i))) {
S = S + s.substring(i-1,i);
}
System.out.println(S);
System.out.println("Please enter a string:");
String t = Riley.nextLine();
String T = "";
for (int i=1; i<=t.length()-1; i+=2) {
T = T + t.substring(i,i+1);
}
System.out.println(T);
System.out.println("Please enter a string:");
String u = Riley.nextLine();
for (int i=0; i<=u.length()-1; i++) {
switch (u.substring(i,i+1)) {
case "a": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "e": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "i": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "o": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "u": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "A": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "E": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "I": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "O": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
case "U": u = u.substring(0,i) + "_" + u.substring(i+1,u.length()); break;
default: break;
}
}
System.out.println(u);
System.out.println("Please enter a string:");
String v = Riley.nextLine();
int V = 0;
for (int i=0; i<=v.length()-1; i++) {
switch (v.substring(i,i+1)) {
case "a": V++; break;
case "e": V++; break;
case "i": V++; break;
case "o": V++; break;
case "u": V++; break;
case "A": V++; break;
case "E": V++; break;
case "I": V++; break;
case "O": V++; break;
case "U": V++; break;
default: break;
}
}
System.out.println("The number of vowels in your string is " + V);
System.out.println("Please enter a string:");
String w = Riley.nextLine();
for (int i=0; i<=w.length()-1; i++) {
switch (w.substring(i,i+1)) {
case "a": System.out.println("The posistion of letter a is " + (i+1)); break;
case "e": System.out.println("The posistion of letter e is " + (i+1)); break;
case "i": System.out.println("The posistion of letter i is " + (i+1)); break;
case "o": System.out.println("The posistion of letter o is " + (i+1)); break;
case "u": System.out.println("The posistion of letter u is " + (i+1)); break;
case "A": System.out.println("The posistion of letter A is " + (i+1)); break;
case "E": System.out.println("The posistion of letter E is " + (i+1)); break;
case "I": System.out.println("The posistion of letter I is " + (i+1)); break;
case "O": System.out.println("The posistion of letter O is " + (i+1)); break;
case "U": System.out.println("The posistion of letter U is " + (i+1)); break;
default: break;
}
}
}
}