Saturday, 1 December 2012

To display each word in the string in reverse order


import java.io.*;
class string38
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s,k="",p="";
int i,l,c=0,c1=0,j;
    System.out.println("Enter the string : - ");
    s=br.readLine();
    s=s+" ";
    l=s.length();
System.out.println("The each extracted word in reverse from are from the upper string are as follows : - ");  
for(i=0;i<l;i++)
{
if(s.charAt(i)!=' ')
{
k=k+s.charAt(i);
}
else
{
for(j=k.length()-1;j>=0;j--)
{
p=p+k.charAt(j);
    }
System.out.print(p+" ");
c1=0;
p="";
k="";
}
}
}
}

No comments:

Post a Comment