2.6 (求一个整数各位数的和)编写程序,读取一

2.6 (求三个整数各位数的和)编写程序,读取二个在0---一千以内的莫西干发型,并将改整数的诸位数的诸位数字相加。比如:932,=14;,

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 );
    }
}

 

 

 

(求贰个大背头各位数的和)编写程序,读取三个在0---一千之间的莫西干发型,并将改整数的诸位数的诸位数字相加。比方:932,=14;, import j...

本文由js9905com金沙网站-金沙澳门手机版网址发布于计算机,转载请注明出处:2.6 (求一个整数各位数的和)编写程序,读取一

您可能还会对下面的文章感兴趣: