public static int sumDigitsInNumber(int number) {
//在此编写你的代码
int i = 0;
int sum = 0;
while(true){
if(number == 0){
break;
}
i = number%10;
number = number/10;
sum += i;
}
return sum;
}
package zh.codegym.task.task01.task0132;
/*
三位数的数字和
*/
public class Solution {
public static void main(String[] args) {
System.out.println(sumDigitsInNumber(546));
}
public static int sumDigitsInNumber(int number) {
//在此编写你的代码
int i = 0;
int sum = 0;
while(true){
if(number % 10 == 0){
break;
}
i = number%10;
number = number/10;
sum += i;
}
return sum;
}
}