逆序输出一个整数
int a = in.nextInt(); int count = 0; do { count = count *10 +a %10; a /=10; }while (a>0); System.out.println(count);
int a = in.nextInt(); int count = 0; do { System.out.print(a%10); a/=10; }while (a>0);
正序输出一个已知位数的整数
//已知: //n 是x的位数 int n =4; // mode:10的n-1次方 int mode = 1000; int x = in.nextInt(); for(int i=0;i<n;i++) { System.out.println(x/mode); x%=mode; mode /=10; }