I need to validate the user's input so that the value entered is a double or an int; then store the int/double values in an array and show an error message if the user enters invalid data.
For some reason my code crashes if the user enters invalid data.
Could you please review my code below and tell me what is possibly wrong?
public static double[] inputmethod() {
double list[] = new double[10];
Scanner in = new Scanner(System.in);
double number;
System.out.println("please enter a double : ");
while (!in.hasNextDouble()) {
in.next();
System.out.println("Wrong input, Please enter a double! ");
}
for (int i = 0; i < list.length; i++) {
list[i] = in.nextDouble();
System.out.println("you entered a double, Enter another double: ");
}
return list;
}