java采用取余方式拿到后面的数
数字颠倒
http://www.nowcoder.com/questionTerminal/ae809795fca34687a48b172186e3dafe
a%10取个位然后输出,a/=10去掉个位,循环直到输出所有数字。
import java.util.Scanner;
public class Main{
public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); if(n == 0){ System.out.println(0); } int yu = 0; while(n != 0){ yu = n % 10; n = n / 10; System.out.print(yu); } } }
}