Java program to accept a sentence and extract the palindrome words.

 Java program to accept a sentence and extract the palindrome words.

import java.util.Scanner;
public class demo{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the String: ");
        String str = sc.nextLine();
        sc.close();
        String strArray[] = str.split(" ");
        for(String temp : strArray) {
            int j = temp.length()-1;
            for(int i=0;i<temp.length()/2;i++) {
                if(temp.charAt(i) != temp.charAt(j))
                    break;
                System.out.println(temp);
            }
           
        }
    }

Comments