代码:
运行结果:
源码:
public class day1 {
public static void main(String[] args){
int number = 1234,number1,number2,number3,number4,number5;
number1 = number%10;
number2 = number/10;
number2 = number2%10;
number3 = number/100;
number3 = number3%10;
number4 = number/1000;
number4 = number4%10;
number5 = number1 + number2 + number3 + number4;
System.out.println("1234四位数的位数和为" + number5 );
}
}
/*
求四位数字的千位数:int number1=number/1000;
求四位数字的百位数:int number2=(number/100)%10;
求四位数字的十位数:int number3=(number/10)%10;
求四位数字的个位数:int number4=number%10;
*/