Count palindrome words in a sentence: Best program
Check some more java programs https://wordpress-343193-1101484.cloudwaysapps.com/julian-day-program
Palindrome words remain the same after reversing also. Like "mom"-->after you reverse the word it is "mom" only.
Write a program to accept a sentence and count the number of words that are palindrome in the sentence.
Check some more java programs
An essential Julian Day Program
import java.io.*;
public class PalindromeWords
{
String str="";
void compute()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the sentence");
str=br.readLine();
if(str.endsWith("."))
str=str.substring(0,str.length()-1);
int count=0;
int len=str.length();
String st="";
String arr[]=str.split("\\s+");
int l=arr.length;
for(int i=0;i<l;i++)
{
st=arr[i];
if(palindrome(st)==true)
count++;
}
System.out.println("The number of palindrome words are"+" " + ""+count);
}
boolean palindrome(String c)
{
int n=c.length();
String s="";
for(int i=(n-1);i>=0;i--)
{
s+=c.charAt(i);
}
s=s.trim();
if(s.equalsIgnoreCase(c))
return true;
else
return false;
}
public static void main()throws IOException
{
PalindromeWords obj=new PalindromeWords();
obj.compute();
}
}Output:
Enter the sentence
My mom and dad are very kind.
The number of palindrome words are 2
Watch java videos here
https://www.youtube.com/user/trushnatej
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.