import javax.swing.*;
public class TestHuiwen{
public static void main(String [] args)
{
String str = JOptionPane.showInputDialog("请输入字符串");
if(booleanIsPalindrome(str))
{
JOptionPane.showMessageDialog(null, str+"是回文", "结果", JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, str+"不是回文", "结果", JOptionPane.INFORMATION_MESSAGE);
}
}
public static String qubiaodian(String s){
char [] chs = s.toCharArray();String temp="";
for(int i=0;i<chs.length;i++)
{
if(chs[i]>='A' &&chs[i]<='Z'|| chs[i]>='a'&&chs[i]<='z'||chs[i]>='0'&&chs[i]<='9')
{
temp+=s.charAt(i);
}
}
return temp;
}
public static boolean booleanIsPalindrome(String str){
String temp="",str1,str2;
str1=qubiaodian(str);
str2=str1.toLowerCase();
boolean flag=false;
for(int i=str2.length()-1;i>=0;i--)
{
temp+=str2.charAt(i);
}
if(temp.equals(str2))
{
flag=true;
}
return flag;
}
}
public class TestHuiwen{
public static void main(String [] args)
{
String str = JOptionPane.showInputDialog("请输入字符串");
if(booleanIsPalindrome(str))
{
JOptionPane.showMessageDialog(null, str+"是回文", "结果", JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, str+"不是回文", "结果", JOptionPane.INFORMATION_MESSAGE);
}
}
public static String qubiaodian(String s){
char [] chs = s.toCharArray();String temp="";
for(int i=0;i<chs.length;i++)
{
if(chs[i]>='A' &&chs[i]<='Z'|| chs[i]>='a'&&chs[i]<='z'||chs[i]>='0'&&chs[i]<='9')
{
temp+=s.charAt(i);
}
}
return temp;
}
public static boolean booleanIsPalindrome(String str){
String temp="",str1,str2;
str1=qubiaodian(str);
str2=str1.toLowerCase();
boolean flag=false;
for(int i=str2.length()-1;i>=0;i--)
{
temp+=str2.charAt(i);
}
if(temp.equals(str2))
{
flag=true;
}
return flag;
}
}