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

HW5.2

时间:2016-08-20 00:05:43      阅读:170      评论: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         System.out.print("Enter the number: ");
 9         long number = input.nextLong();
10 
11         input.close();
12 
13         System.out.println("The sum of the number is " + sumDigits(number));
14     }
15 
16     public static long sumDigits(long n)
17     {
18         if(n < 10)
19             return n;
20         else
21             return n % 10 + sumDigits(n / 10);
22     }
23 }

 

HW5.2

标签:

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

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