I was wondering how I can compare the input from a scanner, to an array. Sorry if this is an easy question, but I'm fairly new to Java.
Here's what I've written:
public static void handleProjectSelection() {
Scanner getProjectNum = new Scanner(System.in);
int answer;
int[] acceptedInput = {1, 2, 3};//The only integers that are allowed to be entered by the user.
System.out.println("Hello! Welcome to the program! Please choose which project" +
"you wish to execute\nusing keys 1, 2, or 3.");
answer = getProjectNum.nextInt(); //get input from user, and save to integer, answer.
if(answer != acceptedInput[]) {
System.out.println("Sorry, that project doesn't exist! Please try again!");
handleProjectSelection();//null selection, send him back, to try again.
}
}
I want the user to only be able to input 1, 2, or 3.
Any help would be appreciated.
Thank you.
acceptedInput[i]for each index of the array.