你的位置:首页 > Java教程

[Java教程]2.6 (求一个整数各位数的和)编写程序,读取一个在0

import java.util.Scanner;public class Demo_1{ public static void main(String[] agrs) {  Scanner input = new Scanner(System.in);  System.out.print("Enter a number 0 and 1000: ");  int number = input.nextInt();  int numbera = number % 10;  int numberb = number / 10;  int numberc= numberb % 10;  int numberd= numberc % 10;    int sum = numbera + numberc + numberd;  System.out.println("The sum of the digits is " + sum ); }}