本文共 409 字,大约阅读时间需要 1 分钟。
import java.util.Scanner;public class java03 { // 控制台输入5位整数,求各个位数上的和 public static void main(String[] args) { // 从键盘中读取输入数据 Scanner m = new Scanner(System.in); System.out.println("请输入一个五位整数"); int a = m.nextInt(); // 取各个位上的值 int g = a % 10; int s = a / 10 % 10; int b = a / 100 % 10; int q = a / 1000 % 10; int w = a / 10000; // 合并各个位的值并输出 int sum = g + s + b + q + w; System.out.println(sum); }}
转载地址:http://ovnwi.baihongyu.com/