输入一个由4位数字组成的整数,把它分解为单个数字,然后输出每一位数字。

代码:

 1 import java.util.*;
 2 public class Main {
 3     public static void main (String [] args) {
 4         Scanner sc=new Scanner(System.in);
 5         int x,a,b,c,d;
 6         x=sc.nextInt();
 7         a=x%10;
 8         x=x/10;b=x%10;
 9         x=x/10;c=x%10;
10         x=x/10;d=x%10;
11         System.out.printf("个位数=%d,十位数=%d,百位数=%d,千位数=%d\n",a,b,c,d);
12     }
13 }

猜你喜欢

转载自www.cnblogs.com/fandehui/p/11050657.html