码迷,mamicode.com
首页 > 其他好文 > 详细

HW2.6

时间:2016-08-06 14:22:54      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW2.6

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5743858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!