eg1:Java获取一个整数的个位上的数(运算符)

Test.java

package Hcybx;

public class Test {
	public static void main(String[] args) {
		int integer = 54321;
		int units = 54321 % 10; // 个位
		int tens = 54321 / 10 % 10; // 十位
		int hundreds = 54321 / 100 % 10; // 百位
		int thousands = 54321 / 1000 % 10;// 千位
		int tenThousands = 54321 / 10000;//万位
		// 依此类推
		System.out.println("个位是:" + units);
		System.out.println("十位是:" + tens);
		System.out.println("百位是:" + hundreds);
		System.out.println("千位是:" + thousands);
		System.out.println("万位是:" + tenThousands);

	}
}

运行结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42635052/article/details/89134917