Create a New Project named StringDemo

Lab 9 Text Processing Objectives Learn how to use String methods Key Concepts 􀁸 The String class provides several methods for working with String objects. Lab Assignment This lab assignment will ask you to write a program prints a String object backward and counts the number of words it contains. Exercise 1 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.)
Powered by