/* * Converts the string "I drank java on the island of Java" into * the string "On the island of xava I drank Xava" * * Illustrates: * - The use of methods in the String class * - Using the same variable on the left and right side of the assignment operator */ public class Java{ public static void main(String[] args){ String phrase = new String("I drank java on the island of Java"); System.out.println(phrase); // Java is case-sensitive phrase = phrase.replace('j', 'x'); phrase = phrase.replace('J', 'X'); // Grab the "o" and upper case it String firstLetter = phrase.substring(13,14); firstLetter = firstLetter.toUpperCase(); // Grab the two parts of the sentence String part1 = phrase.substring(14); String part2 = phrase.substring(0, 13); // Put it all together String finalString = firstLetter + part1 + " " + part2; // Note: If we wanted to be truly hard core, we could use the substring // method to get a space instead of using a string literal " " System.out.println(finalString); } }