package com.test.base;
import java.util.Scanner;
/**
* 〈获取一个数字的各个位置的值〉
*
* 思路:输入一个数字
* 两位数,取前面的值,就除10,取后面的值就取模10
* 同理,如果是多为数,取数字的第一个值,就除以这个数的整百值
* 取最后一个就取模10
* @author PitterWang
* @create 2020/4/20
* @since 1.0.0
*/
public class NumberLocation {
public static void main(String[] args) {
//输入一个数字
Scanner scanner = new Scanner(System.in);
int sy = scanner.nextInt();
NumberLocation.getNumberLocation(sy);
}
public static void getNumberLocation(int sy) {
int bei = sy / 100;
int shi = (sy/10) % 10; //除以10就转int就剩下百位和十位,再取模10就剩下十位了
int shi1 = (sy%100) / 10; //取模100剩下十位和个位了,再除以10,就剩下十位了。
int ge = (sy / 1) % 10;
System.out.println("bei= " + bei);
System.out.println("shi= " + shi);
System.out.println("shi1= " + shi1);
System.out.println("ge= " + ge);
}
}
获取一个百数字的各个位置的值
最新推荐文章于 2023-03-16 17:44:24 发布