Learn how to use String methods
The String class provides several methods for working with String objects.
This lab assignment will ask you to write a program prints a String object backward and counts the number of words it contains.
1. Create a New Project named StringDemo
2. Write a method called “backward()” that accepts a String object as an argument and displays its contents backward. For instance, if the string argument is “gravity” the method should display -“ytivarg”. Demonstrate the method in a program that asks the user to input a string and then passes it to the method.
3. Write a method called “wordCount()” that accepts a String object as an argument and returns the number of words it contains. In this case, we will assume blank spaces separate words. For instance, if the argument is “Four score and seven years ago” the method should return the number 6. Demonstrate the method in a program that asks the user to input a string and then passes it to the method. The number of words in the string should be displayed on the screen. (Hint: the split() String method could be useful.)Attachments
int numberOfWords = wordCount(input);
// Call word count
System.out.println("The string has " + numberOfWords + " words in it.");
* Word count should return the number of words contained within a