我知道如何要求用户输入正整数,但我不知道如何处理代码以避免输入错误,例如小数或字符串输入。
int seedValue;
double angle, gunpowder;
System.out.println("Please enter a positive integer seed value: ");
seedValue = input.nextInt();
while (seedValue <= 0) {
System.out.println("Please enter a positive integer seed value: ");
seedValue = input.nextInt();
}
System.out.println("That target is " +
threeDec.format(gen.nextDouble() * 1000) + "m away.");