Monday 2 November 2015

Reverse an Order Of a String Using JAVA

Reverse an Order Of a String Using JAVA

In this post i am going to show you how to reverse the order of the given string. the order of the string will be reverse means the last whole word become the first and first become the last word of the string and other remaining word also change the position in the order they appear.

Example: jiten vaghela
ouput: vaghela jiten

Download Program: Click here

Program:

import java.util.*;

public class reverseOrder{
public static void main(String [] args){
Scanner input=new Scanner(System.in);
System.out.print("Enter your String:");
String data=input.nextLine();
String [] arrayData=data.split(" ");

data=new String("");
for(int i=arrayData.length-1;i>=0;i--){
data+=arrayData[i]+" ";
}
System.out.println("Reverse String:"+data);
}
}

output:


No comments:

Post a Comment