Question: *Code in Java* Task 1: Given a String of words, separated by a space, determine the number of words in the String. (2 points) For

 *Code in Java* Task 1: Given a String of words, separatedby a space, determine the number of words in the String. (2

*Code in Java*

Task 1: Given a String of words, separated by a space, determine the number of words in the String. (2 points) For example: String inputString = "My name is University of Pittsburgh"; Your output should be: There are a total of 6 words Tips: 1. Ask the user for input using JOptionPane.showinputDialog(). 2. You are not required to print or do anything else with the String, just print a sentence with the number of words. 3. Use the number of spaces to help you determine the number of words in the sentence. Task 2: Given a string of text, write a for loop that prints the text inverted. For example: String inputString = "Pittsburgh"; Your output should be: hgrubsttip Tips: 1. There are two ways you can approach this task. You can change the string in place by swapping characters or create a new string that starts the last character of the input string. 2. You can use the charAt() method to get the character at a specific position. Task 3: A palindrome is a word, phrase, or sequence that reads the same backward as forward. For example, the word madam or the phrase "nurses run" are both palindromes. Given a single word (case insensitive), determine if it is a palindrome. a. Ask the user for a word b. In the console window, print out [word] is a palindrome" or "[word] is not a palindrome" Given: "civic" Given: "name" Given: Madam" Output: civic is a palindrome. Output: name is not a palindrome. Output: Madam is a palindrome. Tips: 1. One way to check if a word is a palindrome is to copy the word to another string and then use your method from task 2 above to reverse the second string. Then use String comparison to determine if they are the same. 2. Another way to approach this is to loop through the word and compare each character. So for example, for the string "civic", you'd compare the positions at (0,4) then (1,3) and then output "is a palindrome". Since the word length is odd, you don't compare the middle character (v) to anything else. For the word "hello", you'd compare the characters at position (0,4) and determine that they are different and then exit your loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!