how to reverse a santance using java

 

I want to reverse the sentence like
how are you -> you are how


Answer
 

-public class test {
    public static void main(String args[])
    {

        String x=" how are you";
       
          String y[]=x.split(" ");
      
          for(int i=y.length-1;i>=0;i--)
        {
            System.out.print(y[i]+ " ");
        }
    }
}

O/P-you are how


 


String s = "SR Global Infotech";

String[] split = s.split(" ");

String result = "";

for (int i = split.length - 1; i >= 0; i--)
 {
  result += (split[i] + " ");

}

System.out.println(result.trim());

O/P-Infotech Global SR