This is a project for my class and I'm new to coding. It works if valid user input is done the first time but generates exception when invalid input is done (error info at the bottom). I swear i had this working correctly a few days ago.
import java.util.Scanner;
public class DingDong {
public static void main(String[] args) {
boolean done;
do {
int n1,n2;
Scanner kb = new Scanner(System.in);
System.out.print("Enter two integers between 2 and 15 (included): ");
n1 = kb.nextInt();
n2 = kb.nextInt();
if (!((!(n1 < 2) && !(n1 > 15)) && (!(n2 < 2) && !(n2 > 15)))) {
done = false;
System.out.print("Invalid input. Please try again.");
} else {
done = true;
double i = 1;
while (i <= 50){
if ((i/n1 % 1 == 0) && (i/n2 % 1 == 0)){
System.out.printf("DingDong ");
} else if (i/n1 % 1 == 0){
System.out.printf("Ding ");
} else if (i/n2 % 1 == 0){
System.out.printf("Dong ");
} else {
System.out.printf("%.0f ", i);
}
i++;
}
}
kb.close();
} while (!done);
}
}
Invalid input. Please try again.Exception in thread "main" Enter two integers between 2 and 15 (included): java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at DingDong.main(DingDong.java:11)
Thank you for any input.
Wish i knew how to delete this post now.