The Code
import java.util.Scanner;
public class StringDemo {
public static void main(String[] args) {
String word = "hello";
System.out.printf("%s is the word\n",word);
String phrase = "";
Scanner myScanner = new Scanner(System.in);
while (!phrase.equalsIgnoreCase("quit")) {
System.out.print("Enter a phrase = >");
phrase = myScanner.nextLine();
System.out.printf("The scanner got '%s'\n",phrase);
System.out.printf("That is %d letters long.\n", phrase.length());
System.out.printf("As upper case: '%s'\n", phrase.toUpperCase());
System.out.printf("But Phrase did not change: '%s'\n",phrase);
System.out.printf("As lower case: '%s'\n", phrase.toLowerCase());
if (phrase.length() > 3) {
int middle = phrase.length()/2;
String middleLetters = phrase.substring(middle-1, middle+2);
System.out.printf("The middle of the string is '%s'\n",middleLetters);
}
System.out.println();
int i = 0;
while(i < phrase.length()){
System.out.printf("%c is at %d\n",phrase.charAt(i), i);
++i;
}
System.out.println();
}
}
}