/*Programmer Name: Jhovan C. BesasProgram Name: Hello ObjectPurpose: To enhance how to run a program that will reverse the outputDate: March 18,2009Instructor: Dony Dongiapon*/
import javax.swing.*;
import java.util.Scanner;
import java.io.*;
public class Reverse {
public static void main(String[] args) throws IOException//start the main method that will catch Exceptions
{
String a=JOptionPane.showInputDialog("Enter a Name: ");//ask input to the user in correct form
System.out.print("Input:"+a);//print output of the user
String b=a.substring(a.indexOf(" "),a.length());
String reverse= new StringBuffer(b).reverse().toString();//reverse the first word entered
String c=a.substring(0,a.indexOf(" "));
String reverse2=new StringBuffer(c).reverse().toString();//reverse the second word entered
System.out.println("\nInput in Normal Form : " + a);// Print the normal string
System.out.println("Reverse input: " +reverse2+ " "+ reverse );// Print the string in reversed order
}//end main method
}//end class Reverse
Sample Output:
Enter name: vhan d'best
Input in Normal Form: vhan d'best
Reverse input: nhav tseb'd
No comments:
Post a Comment