COMPUTER SCIENCE....
Write a program in java to input 4 words in array and print only palindrome words.....
Answers
Answered by
2
import java.util.Scanner; class Pa{ public static void main(String[] args){ Scanner sc = new Scanner (System.in); String s=sc.nextLine(); char b; int i,a; String st="";/to extract a word s=s+" "; String t="";/to extract the reverse of the word a=s.length(); for(i=0;i<a;i++){ b=s.charAt(i); if(b!=' '){ st=st+b;/word t=b+st;/reversed word } else { if(st.equals(t)){ System.out.println(st); } st=""; t=""; } } } }
Similar questions