输入一个四位数,求各个位之和:如1234 结果为1+2+3+4=10;
package test1; import java.util.Scanner; public class one { public static void main(String[] args) { Scanner out=new Scanner(System.in); System.out.println("输入一个整数:"); int a=out.nextInt(); int b,c,d,e; b=a/1000; c=(a-b*1000)/100; d=(a-b*1000-c*100)/10; e=a%10; System.out.println("各个位数的和是"+(b+c+d+e)); } }