我正試圖找到0 &給定輸入之間的迴文數字。代碼中有一些錯誤。我認爲問題在於邏輯。查找回文數字
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
int count = 0;
System.out.println("Enter the limit to check the no of Palindrome ");
Scanner input = new Scanner(System.in);
int no = input.nextInt();
for (int j = 0; j <= no; j++) {
if (number(j)) ;
++count;
}
System.out.println(count);
}
public static boolean number(int num) {
int i = num;
int reverse = 0;
while (i != 0) {
reverse = reverse * 10;
reverse = reverse + i % 10;
i = i/10;
}
if (num == reverse) {
return true;
} else
return false;
}
}
請列出錯誤。 –