📜  java 检查它是否是数字扫描仪 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:27.595000             🧑  作者: Mango

代码示例1
Scanner sc = new Scanner(System.in);
int number;
do {
    System.out.println("Please enter a positive number!");
    while (!sc.hasNextInt()) {
        System.out.println("That's not a number!");
        sc.next(); // this is important!
    }
    number = sc.nextInt();
} while (number <= 0);
System.out.println("Thank you! Got " + number);