import java.io.*;
class string41
{
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 palindrome word in 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);
}
if(k.equals(p))
{
System.out.println(k);
}
c1=0;
p="";
k="";
}
}
}
}
Reverse the sentence as the following example:
ReplyDeleteINPUT:I and Ayush
OUTPUT:Ayush and I
Please can you do this program