Thursday, March 19, 2009

Exercise1- Word Reverser

/*Programmer: Rosedil Mae P. Mobreros
*Date started: March 16, 2009
*Date ended: March 19, 2009
*Purpose: To create a program that access sentence from the user and prints it out with each word in reversed form.*/

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

String roxy;
String key;

Scanner scan=new Scanner(System.in);
System.out.println("Key in desired word:");
input=scan.nextLine();
StringTokenizer k=new StringTokenizer(key);
while (k.hasMoreTokens())
{
roxy=k.nextToken();
roxy=new StringBuffer(k).reverse().toString();
System.out.print(k+" ");

}

}
}

No comments:

Post a Comment