
i am giving the string=" i am sachin".for this output is "sachin am i".please give me the code?

Hi Friend,
Try the following code:
import java.util.*;
class ReverseWords{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.nextLine();
StringBuffer buffer=new StringBuffer();
String str[]=st.split(" ");
for(int i=str.length-1;i>=0;i--){
buffer.append(str[i]);
buffer.append(" ");
}
System.out.println(buffer.toString());
}
}
Thanks

Hi Friend,
Try the following code:
import java.util.*;
class ReverseWords{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.nextLine();
StringBuffer buffer=new StringBuffer();
String str[]=st.split(" ");
for(int i=str.length-1;i>=0;i--){
buffer.append(str[i]);
buffer.append(" ");
}
System.out.println(buffer.toString());
}
}
Thanks

Hi friend try this code ...........
**public class Class1 { public static void main(String args[]) { String str1 = "India is great"; String strArray [] = str1.split(" "); String result = ""; for (int i = strArray.length -1; i>=0; i--) result = result + " "+strArray[i] ; System.out.println("the reversed is" + result); } }**