Write a program in Java to enter a String and display all the palindrome words present
in the String
Sample Input : MOM AND DAD ARE NOT AT HOME
Sample Output:MOM
DAD
Attachments:
Answers
Answered by
2
Answer:
import java.util.*;
class palindrome
{
public static void main(String args[])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter the string:");
String s=sc.nextLine();
StringTokenizer ob=new StringTokenizer(s);
int l=ob.countTokens();
System.out.println("The Palindrome Words Are:");
for(int i=0;i<l;i++)
{
String m=ob.nextToken();
String n="";
int len=m.length();
for(int j=0;j<len;j++)
n=m+n;
if(n==m)
System.out.print(m+" ");
}
}
}
Explanation:
anshikajais2001:
then you can make a seperate function with return type int and send each word from the string using substring to that function and check if it's palindrome or not. use a flag variable to return 1 if it is palindrome else 0.
Answered by
0
Explanation:
Heyy...i have brought this for u...and easy way of doing the program
Please like it and mark it as a brainlist if you liked it...
Attachments:
Similar questions