Tuesday, March 17, 2009

Word Reverses

Exer.1 Word Reverses
/*
Programmer: Albert Ampo
Date Started: March 17,2009
Date Ended: March 18, 2009

*/

import java.util.Scanner;
import java.io.*;
import java.lang.StringBuffer;
public class reverse {
   
 
  public static void main(String[] args) throws IOException
  {
  // The normal sentence that is going to be reversed.
  System.out.print("Enter Name: ");
  Scanner in=new Scanner(System.in);
  String words = in.nextLine();
   
   
   
  String Word1=words.substring(words.indexOf(" "),words.length());
  String reverse= new StringBuffer(Word1).reverse().toString();
  String Word2=words.substring(0,words.indexOf(" "));
  String 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 );
  }

}

Input: albert ampo

trebla opma

No comments:

Post a Comment