Computer Science, asked by allenmathews, 11 months ago

using a scanner class write a program to accept a sentence and display only palindrome words​

Answers

Answered by RewelDeepak
0

Answer:

Given a string str and the task is to count palindrome words present in the string str. ... /*C++ program to count number of palindrome ... using namespace std; ... class GFG {.

Answered by Oreki
0

import java.util.Scanner;

public class StringManipulation {

static boolean isPalindrome(String word) {

return word.equals(new StringBuffer(word).reverse( ).toString( ));

}

public static void main(String[ ] args) {

// Accepting sentence and converting it into a String array.

System.out.print("Enter a Sentence - ");

String[ ] sentence = new Scanner(System.in).nextLine( ).split(" ");

// Printing only the words which are Palindrome.

for (String word : sentence)

if (isPalindrome(word))

System.out.println(word);

}

}

Similar questions