下面是一种用 Java 计算三位数各个位数的方法:
public static void main(String[] args) {
int num = 123;
int hundreds = num / 100;
int tens = (num % 100) / 10;
int ones = num % 10;
System.out.println("百位数是:" + hundreds);
System.out.println("十位数是:" + tens);
System.out.println("个位数是:" + ones