博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Java]控制台输入5位整数,求各个位数上的和
阅读量:3942 次
发布时间:2019-05-24

本文共 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/

你可能感兴趣的文章
Lesson2.2 & 2.3 Maya command reference & quick help
查看>>
lesson 2.4 - Converting MEL Commands to Python
查看>>
Lesson3.2 variables
查看>>
3.4.2 - Operators & 3.4.3 division and truncation
查看>>
3.7.1 - Strings
查看>>
3.7.4 - Indexing and Slicing Strings
查看>>
3.7.5 - Modifying Strings
查看>>
3.7.6 - String Methods
查看>>
3.8 - Using the Print Function
查看>>
3.9.1 - Lists in Python
查看>>
3.9.2 - Lists - Adding and Removing Objects
查看>>
3.9.3 - Sorting Lists
查看>>
3.10 - Maya Commands: ls
查看>>
3.11 - Dictionaries in Python
查看>>
3.12 - Tuples in Python
查看>>
4.4 - For Loops
查看>>
4.2.2 - Logical and/or Operators
查看>>
Lesson 4 Part 2 Softmax Regression
查看>>
文章中运用到的数学公式
查看>>
Projective Dynamics: Fusing Constraint Projections for Fast Simulation
查看>>