1 //程序员:马相露 2 3 package demo; 4 import java.util.Scanner; 5 public class Lk { 6 7 public static void main(String[] args) { 8 9 Scanner input = new Scanner(System.in); 10 System.out.println("请输入一个0-1000之间的整数"); 11 int a =(int)input.nextDouble(); 12 13 if(a>999||a<0) { 14 System.out.println("输入有误"); 15 16 } 17 else if(a>0 && a<10){ 18 System.out.println("The sum of the digits is "+ a); 19 } 20 else if(a>9 && a<100) { 21 int b=(a/10) + (a%10); 22 System.out.println("The sum of the digits is "+ b); 23 } 24 else if(a>99 && a<1000) { 25 int c=(a/100)+(a%100)+(a%10%10); 26 System.out.println("The sum of the digits is "+ c); 27 } 28 } 29 30 }