Wednesday, March 18, 2009

Exercise1- Word Reverser

/*Programmer: Miexie D. Tulid
 *Date started: March 13, 2009
 *Date ended: March 18, 2009
 *Description: A program that reads a sentence from the user and prints it out w/ each word
 *reversed.*/


import java.util.*;
public class reverseSent{
public static void main(String args[]){

String input;
String r;
 Scanner scan=new Scanner(System.in);
 System.out.println("Input:");
 input=scan.nextLine();
 StringTokenizer st=new StringTokenizer(input) ;
  while (st.hasMoreTokens()) {
  r=st.nextToken();
  r=new StringBuffer(r).reverse().toString();
  System.out.print(r+" ");
   
  }
   
}
}

No comments:

Post a Comment