Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Text Processing; Learn how to use String Methods

phillyluvr
phillyluvr 


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.) Attachments Tags Clarifications

Answers

StringDemo.java

felo
felo 



Text Processing Attachments
StringDemo.rar (3 K) Download





Preview
for ( int i = length - 1 ; i >= 0 ; i-- ) backward = backward + original.charAt(i);

Preview
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

GRAV.png (164 K) Download Preview

GRAVITYOUT.png (162 K) Download Preview

Screenshots
Screenshot
Screenshot
Purchase Answer