I am trying to figure out the best way to read in 3 integers from 0 to 9 with no spaces. Eventually I will have to check the input to make sure there are no duplicates or letters and that 3 numbers have been entered. This is what I've tried so far. Would it be better to read in the input as a string then put the numbers in an integer array? Any tips would be greatly appreciated.
Scanner guess = new Scanner(System.in);
int[] array = new int[4];
System.out.println("Enter 3 numbers from 0 to 9");
while (guess.hasNextInt()) {
array[i] = guess.nextInt();
i++;
if (i == 3) {
break;
}
}