Computer Science, asked by debasmitajini, 1 year ago

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 anshikajais2001
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.
debasmitajini: ok
anshikajais2001: hope it helps you....btw i guess u r in class 10
debasmitajini: yes
debasmitajini: thanks 4 help
debasmitajini: di help me plz
anshikajais2001: in??
debasmitajini: i got the answer
debasmitajini: one bro helped
anshikajais2001: ok
Answered by atuljha275
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