0% found this document useful (0 votes)
18 views2 pages

Java Palindrome and Word Count Check

The Java program checks if a given string ends with a period or question mark and then verifies if the string is a palindrome by removing non-alphanumeric characters. It also counts the maximum occurrences of any word in the string. If the string does not end with the specified punctuation, it outputs 'Invalid'.

Uploaded by

miglanidivya28
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Java Palindrome and Word Count Check

The Java program checks if a given string ends with a period or question mark and then verifies if the string is a palindrome by removing non-alphanumeric characters. It also counts the maximum occurrences of any word in the string. If the string does not end with the specified punctuation, it outputs 'Invalid'.

Uploaded by

miglanidivya28
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

class Main {

public static void main(String[] args) {


String str = "one am the one am are am is.";
int len = [Link]();
if([Link](".") || [Link]("?"))
{
String strn = "";
for(int i=0;i<len;i++)
{
char ch = [Link](i);
if([Link](ch))
strn = strn + ch;
}
int p=0;int q= [Link]()-1;
int f = 1;
while(p<q)
{
if([Link](p) != [Link](q))
f = 0;

p++;q--;
}
if(f==1)
[Link]("Palindrome");
else
[Link]("Not Palindrome");
int max = 0;
String[] words = [Link](" ");
for(int i=0;i<[Link];i++)
{
int count = 1;
for(int j=i+1;j<[Link];j++)
{
if(words[i].equals(words[j]))
count++;
}
if(count>max)
max = count;
}
[Link]("Max="+max);
}
else
{
[Link]("Invalid");
return;
}
}
}

You might also like