Write a program to accept a string and display only those words which are palindromes
Answers
Answered by
0
Sample Input : MOM AND DAD ARE NOT AT HOME
Sample Output : MOM DAD
import java.util.*;
class Pg200prog1
{
static void teja()
{
Scanner in = new Scanner(System.in);
System.out.print(“Enter the String : “);
String st = in.nextLine();
int l = st.length();
String bin = “”;
for(int i=0;i<l;i++)
{
char ch = st.charAt(i);
if(!(Character.isWhitespace(ch)))
{
bin=bin+ch;
continue;
}
else
if(Character.isWhitespace(ch))
{
int b = bin.length();
int d=bin.charAt(0);
int e = bin.charAt(b-1);
if(d==e)
System.out.print(bin+” “);
bin = “”;
}
}
}
}
Similar questions
India Languages,
6 months ago
English,
6 months ago
Physics,
6 months ago
Social Sciences,
11 months ago
History,
11 months ago
Math,
1 year ago
Science,
1 year ago