public static int reverse(int number)
{
String strnumber=Integer.toString(number);
boolean result;
for(int i=1;i<=strnumber.length()/2;i++)
{
char ch = strnumber.charAt(i-1);
System.out.println(ch);
char ch2 =strnumber.charAt(strnumber.length()-i);
System.out.println(ch2);
if(strnumber.charAt(i-1)==strnumber.charAt(strnumber.length()-i))
{
result = true;
}
else
{
result = false;
break;
}
}
if(result = true)
{
System.out.println("The integer is a palindrome.");
}
else if(result = false)
{
System.out.println("The integer is not a palindrome.");
}
return number;
答案 0 :(得分:3)
if(result = true)
和else if(result = false)
,为结果分配值,而不是比较。 =
是赋值运算符,比较运算符是==
更改以下行:
if(result = true)
{
System.out.println("The integer is a palindrome.");
}
else if(result = false)
{
System.out.println("The integer is not a palindrome.");
}
以强>
if(result == true)
{
System.out.println("The integer is a palindrome.");
}
else if(result == false)
{
System.out.println("The integer is not a palindrome.");
}