Java2.6**

来源:互联网 发布:与av淘宝一样的网站 编辑:程序博客网 时间:2024/05/17 06:27
/*  * Copyright (c) 2014, 烟台大学计算机学院  * All rights reserved.  * 文件名称:test.cpp  * 作    者:刘佳琦  * 完成日期:2015年 9 月 8日  * 版 本 号:v1.0  *  * 问题描述:  * 程序输出:  */import java.util.Scanner;public class Hello{/** * @param args */public static void main(String[] args){// TODO Auto-generated method stubint a;Scanner in=new Scanner(System.in);System.out.print("Enter a number between 0 and 1000:");a=in.nextInt();int b,sum=0;while(a!=0){b=a%10;a/=10;sum+=b;}System.out.println("The sum of the digits is "+sum);}}

 

 

运行结果:


0 0
原创粉丝点击