EXERCISE 1
/* Programmer: Nerissa Agapay
  * Program name: Reverser 
  * Instructor: Mr. Dony Dongiapon 
  * Date Started: 03/16/09 
  * Date Finished: 03/18/09 
  * Description:To reverse the phrase being enter by the user without changing   orginal position of the words.
*/
import java.util.*;
import javax.swing.*;
public class Reverser {
  public static void main(String[] args){
    
   String name=(JOptionPane.showInputDialog("Enter phrase:"));//
    
   StringTokenizer tokens = new StringTokenizer(name);//use StringTokenizer to separate each word.
    while(tokens.hasMoreTokens()){
     
      String element = tokens.nextToken();
      StringBuffer buffer = new StringBuffer(element); // a method that  reverses the contents .
     
      element = buffer.reverse().toString();
     
      System.out.print(element+" "); //print the reverse word .
    }
  }
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment