如上所述,我有兩種方法,我想實現兩個方法來檢查,如果一個號碼是迴文
public static int reverse(int number)
和
public static boolean isPalindrome(int number)
我應該安排他們來檢查號碼是否迴文或不。我試圖應用提示(一個數字是迴文,如果(其反轉==本身)),但它沒有幫助。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("This program checks whether a number is palindrome or not. Enter a number: ");
Scanner input = new Scanner(System.in);
int inputNumber = input.nextInt();
// if inputNumber is palindrome
System.out.println("The number is palindrome.");
// else
System.out.println("The number is not a palindrome.");
}
public static int reverse(int number)
// reverse number
public static boolean isPalindrome(int number)
// check if the number is palindrome
}
}
你試過的代碼在哪裏? – cody123
「但它沒有幫助」 - 爲什麼不呢?這是正確的,所以你的反轉代碼是不正確的。請出示 –
@ q1612749我已添加解決方案。如果它解決了您的問題,請標記正確並注意上傳。另外如果你發佈你的代碼會更好。 – cody123