//testing if a string is equal to its reverse WhileDemo.isPalindrome("Thursday") WhileDemo.isPalindrome("WOW") //we wrote a more efficient version in lecture that doesn't reverse the string //instead compares 1st and last characters, 2nd and 2nd last, etc until it reaches the middle //if all these pairs of chars are equal then it's a palindrome, otherwise not. //Exercise: write the isPalindrom using the more efficient way. //here is how to count the # of occurance of a char in a string: WhileDemo.countChars("hello", "h") WhileDemo.countChars("hello", 'h') WhileDemo.countChars("hello", c) WhileDemo.countChars("hello", 'p') WhileDemo.countChars("hello", 'l') // Testing principles: 0, 1 and many WhileDemo.countChars("", 'h') WhileDemo.countChars("h", 'h') //nested loop! what't the output of mystery? WhileDemo.mystery() //exercise: change the numbers 3 and 2 in the while conditions and predict what happens /*let's do another example of nested loop: *given a string of sentences, using StringTokenizer * Split s into sentences, printing a header for * each sentence, and each word in the sentence * on a different line. */ NestedLoops.sentenceWordSplit("") NestedLoops.sentenceWordSplit(""); NestedLoops.sentenceWordSplit("Today is Monday."); NestedLoops.sentenceWordSplit("Today."); NestedLoops.sentenceWordSplit("Today. Tomorrow."); NestedLoops.sentenceWordSplit(""Today is Thursday. I can't stand a 2-hour lecture.")