Only let users input positive integers (no decimals or strings)?
I know how to ask the user to input positive integers, but I don't know
how approach the code to avoid an input error such as a decimal or string
input.
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.");
No comments:
Post a Comment