Computer Science, asked by kanchetisri2002, 11 months ago

Write a program to accept a string and display only those words which are palindromes

Answers

Answered by mayurikajuthu
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