Wednesday, July 1, 2020

Reverse words in string using Java

Reverse words in a string using Java

PROGRAM:

public class reverse_str_words {
   
    public static void main(String args[])
    {
        String str ="hello world sathish";
       
        String s[]=str.split(" ");
       
        for (int i=s.length-1;i>=0;i-- )
        {
            System.out.print(" "+s[i]);
        }
    }
   

}


OUTPUT:

sathish world hello

No comments:

Post a Comment