Tuesday, March 17, 2009

Word Reverser

ExerCise #1: Word Reverser

//ProgrammerName: Reuben D. matiga
//ProgramName: Word Reverser 
//Purpose: To Learned more in java
//Date: March 17,2009
//Instructor: Dony Dongiapon


 
public class reverse
{
  public static void main(String[] args)
  {
  // The normal sentence that is going to be reversed.
  String words = "Go to the main menu";
   
  String reverse2="";
  String reverse = new StringBuffer(words).reverse().toString();
  String Word1=words.substring(words.indexOf(" "),words.length());
  reverse= new StringBuffer(Word1).reverse().toString();
  String Word2=words.substring(0,words.indexOf(" "));

  reverse2=new StringBuffer(Word2).reverse().toString();


  // Print the normal string

  System.out.println("Normal : " + words);


 // Print the string in reversed order
  System.out.println("Reverse: " +reverse2+ " "+reverse);
  }
}
 

No comments:

Post a Comment