public class Tes {
public static void fun1(int num){
//比较粗暴
int i1 = num/100;
int i2 = (num-i1*100)/10;
int i3 = num-i1*100-i2*10;
System.out.println("百位:"+i1);
System.out.println("十位:"+i2);
System.out.println("个位:"+i3);
}
public static void fun2(int num){
String string = String.valueOf(num);
System.out.println("百位:"+string.charAt(0));
System.out.println("十位:"+string.charAt(1));
System.out.println("个位:"+string.charAt(2));
}
public static void main(String[] args) {
fun1(123);
System.out.println("-----------------");
fun2(123);
}
}
思路:除100结果是百位,原数减去百位值除10是十位,再减最后是个位