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]);
}
}
}
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