Tuesday, March 17, 2009

IT134 ExerCise #1: Word Reverser

Word Reverser 
ExerCise #1: Word Reverser

ProgrammerName: Odoy, Montanio
ProgramName: Word Reverser 
Purpose: To Learned how to print it out with word reversed 
in the punctuation in the original order.
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