我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
import java.util.Scanner;
class p1Q6
{
public static void main(String[] args)
{
int input,sumOfdigits,a,b,c,d;
Scanner scan = new Scanner(System.in);
System.out.println("Please input an integer between 0-1000: ");
input = scan.nextInt();
a = input/1000;
b = (input -a*1000)/100;
c = (input - a*1000 - b*100)/10;
d = input % 10;
sumOfdigits = a + b + c + d;
System.out.println("Sum of digits: "+sumOfdigits);
}
}
导入论坛查看(35)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing