I've comment on the line. Why will that line not take another input? And then keep repeating until an integer is input.
import java.util.*;
class ScanNumbers{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int[] NumberEntry = new int[6];
for (int i = 1; i < NumberEntry.length; i++){
boolean isInteger = false;
while (!isInteger){
try {
System.out.print("Entry " +i + "/5, enter an integer value: ");
NumberEntry[i] = scan.nextInt();
isInteger = true;
}
catch (Exception e){
System.out.print("Entry " +i + "/5, Please enter only an integer value: ");
NumberEntry[i] = scan.nextInt(); //Right here, I would like to ask again, why is this line not doing the job?
}
}
}
Arrays.sort(NumberEntry);
System.out.print("The max integer is: " + + NumberEntry[NumberEntry.length-1]);
}
}
Can't I just tell it to try the catch again?
Edit 1: Haha, Oh my, Thanks, I have removed the line, but now the out put keeps repeating "Entry 1/5, enter an integer value:"
Edit 2: Thanks! Works fine now!