public static void main(String[] args) {
int sum = 0;
char a;
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
if (num < 0 || num > 1000) {
System.out.println("请输入0到1000之间的数字");
return;
}
String str = String.valueOf(num);
for (int i = 0; i < str.length(); i++) {
a = str.charAt(i);
sum += a - '0';
}
System.out.println("这个数各位的和为:" + sum);
}