标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter a number between 0 and 1000: "); 10 11 int number = input.nextInt(); 12 int sum = 0; 13 14 if(number > 0 && number < 1000) 15 { 16 if(number >= 100) 17 sum += number / 100 + number % 10 + (number / 10) % 10; 18 else if(number >= 10) 19 sum += number / 10 + number % 10; 20 else 21 sum += number % 10; 22 } 23 24 System.out.println("The sum of the digits is " + sum); 25 26 input.close(); 27 } 28 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5743858.html