编写程序,读取一个在0和1000之间的整数,并将该整数,并将该整数的各位数字相加。例如:932,各位数字之和为14
imnport java.util.Scanner;
public class Zuoye6{
public static void main(String[] args);
Scanner input = new Scanner(System.in);
System.out.println("Enter a number between 0 and 1000: ");
double number = input.nextDouble();
int u = (int)number % 10;
int i = (number / 10) % 10;
int j = number / 100;
int sum = u + i + j;
System.out.println("The sum of the digits is " + sum);
}
}
这是我编写的代码,大家看看有什么错误。求学霸大神指出错误
PS:运行出错
冥oo冥
相关分类