/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:李晓凯
* 完成日期:2015年 9 月 11 日
* 版 本 号:v1.0
*
* 问题描述:
* 输入描述:
* 程序输出:
*/
import java.util.Scanner;
import javax.swing.JOptionPane;
public class helloworld {
/**
* @param args
*/
public static void main(String[] args) {
int r,sum=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter a number between 0 and 1000:");
int a=input.nextInt();
while(a!=0){
r=a%10;
a=a/10;
sum=sum+r;
}
System.out.println("the sum of all its digits is "+sum);
}
这是一个以前经常练习的题目,以前用c++做得很6,然后把它搬到了Java上来,基本上还是一样的代码,真不愧都说有了一门语言的基础,学习另一门语言就很容易了,加油!