Finding out number of Palindromes in a Sentence
I have tried to do a program to find number of palindromes in a sentence but couldn't complete it since I doesn't know to reverse the string and also to remove special characters. Please help!
My code:
import java.io.*;
import java.lang.*;
class palindrome1
{
public static void main(String args[])
{
System.out.println("Welcome");
getsentence();
}
public static void getsentence()
{
try
{
String sent=" ";
String s1=" ";
String[] punct={".",",","?","!"};
String input=" ";
String[] temp;
String[] temp1={ } ;
String[] revstrng;
int i=0;
String delimiter=" ";
int len=0;
System.out.println("Enter the Sentence to find Palindrome Count:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
sent=in.readLine();
s1=sent.toLowerCase();
System.out.println("The entered sentence is:" + s1);
temp=s1.split(delimiter);
for(int j=0;i<temp.length;i++)
{
System.out.println(temp[i]);
if(temp1[i]==(temp[i].reverse()))
{
i++;
}
System.out.println("Number of Palindromes in Sentence:" + i);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}