思路:
比如 n =1234;
那麼如何獲取4,應該 n%10;
那麼如何獲取3,獲取3之前應該刪除4,所以n/10;
//40 +3 =43
//43*10 = 430>430+2(432)>432*10(4320)+1
r=0
怎麼獲取40:r *10 +d
看程式碼:
1 public class test2 { 2 public static void main(String[] args) { 3 int r = 0; 4 int input =1234; 5 int n =input %10; 6 input = input / 10; 7 r= r *10 +n; 8 System.out.println(r); 9 System.out.println(input); 10 n = input %10; 11 input = input / 10; 12 r =r *10 +n; 13 System.out.println(r); 14 System.out.println(input); 15 n = input %10; 16 input = input /10; 17 System.out.println(n); 18 System.out.println(input); 19 } 20 }
完整程式碼:
public static void number_1( int number){ int r =0; int o = number; while (number!=0){ int n =number %10; number =number /10; r = r *10 + n; } boolean is = (r ==0 *2); System.out.println(is); }