There is a 2d array called data that represent a matrix with l lines and c columns. I want to save the matrix numbers with a scanner.
but when the user try to type 1.5 I want to catch the exepction, and ask the user for a new valid number, of course without continue to the next number. I try this code. but when I type for example 1.5 , I got a flood "Please enter a valid integer number".
how Can I make it work right?
thank you for help :)
for (int l=0;l<data.length;l++) {
for (int c=0;c<data[0].length;) {
try {
int num = scanner.nextInt();
data[l][c] = num;
c++;
}
catch(RuntimeException e) {
System.out.println("Please enter a valid integer number");
}
}
}