案例:数值拆分
需求:拆分三位数,把个位、十位、百位分别输出
public class Test3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入一个三位数:"); int num = scanner.nextInt(); int ge = num % 10; int shi = num / 10 % 10; int bai = num /100; System.out.println("个位是:" + ge + ",十位是:" + shi + ",百位是:" + bai); } }