写一个程序,要求输入一个数字,数字中包含5个数位。把数字分解成单独的数位,并打印每一个数位。例如,假定用于键入43263这个数字,那么程序应打印结果:4 3 2 6 3。
Scanner scan=new Scanner(System.in); System.out.println("请输入一个数字: "); int n=scan.nextInt(); //从后往前取 String s=""; while (n>0){ int y=n%10; s=y+" "+s; n=n/10; } System.out.println(s);