import javax.swing.JOptionPane;
public class Chek1{
public static void main(String[] arsg){
String s=JOptionPane.showInputDialog(null,"Enter a string:","Example 7.1 Input",JOptionPane.QUESTION_MESSAGE);
String output=" ";if (rererse(s)==s)
output=s+" is a palindrome";
else
output=s+" is not a palindrome";
JOptionPane.showMessageDialog(null,output,"Example 7.1 Input",JOptionPane.QUESTION_MESSAGE);
}
public static String rererse(String s)
{
int low=0;
int high=s.length()-1;
String t="";while(low<=high){
t+=s.substring(high,high);high--;
}
return t;
}
}
public class Chek1{
public static void main(String[] arsg){
String s=JOptionPane.showInputDialog(null,"Enter a string:","Example 7.1 Input",JOptionPane.QUESTION_MESSAGE);
String output=" ";if (rererse(s)==s)
output=s+" is a palindrome";
else
output=s+" is not a palindrome";
JOptionPane.showMessageDialog(null,output,"Example 7.1 Input",JOptionPane.QUESTION_MESSAGE);
}
public static String rererse(String s)
{
int low=0;
int high=s.length()-1;
String t="";while(low<=high){
t+=s.substring(high,high);high--;
}
return t;
}
}
public static boolean isPalindrome(String s)
{
int i=0,j=s.length()-1;
while(i<j)
{
if(s.charAt(i)!=s.charAt(j))
{
return false;
}
i++;j--;
}
return true;
}
{
char[] ch=s.toCharArray();
int low=0;
int high=s.length()-1;
char t;
while(low <high){
t=ch[low];
ch[low]=ch[high];
ch[high]=t;
low++;
high--;
}//while
return String.valueOf(ch);
} 另外:将:if (rererse(s)==s)
改为:if(rererse(s).equals(s))以上仅供你参考