public class reversewords {
public static void main(String args[])
{
String s="my name is nimit goyal";
char a[]=s.toCharArray();
int x=s.length();
int count=0;
for(int i=s.length()-1 ;i>-1;i--)
{
if(a[i]==' ' ||i==0)
{ //System.out.print("hello");
if(i==0)
{System.out.print(" ");}
for(int k=i;k<x;k++)
{
System.out.print(a[k]);
count++;
}
x=i;
}count++;
}
System.out.println("");
System.out.println("total run =="+count);
}
}
output: goyal nimit is name my
total run ==46