问题:输入一个整数,计算它各位上数字的和
Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int sum = 0; while(a!=0){ sum = sum+a%10; a=(int)a/10; } System.out.println(sum);