Hello everyone, I知 having some issue with my code. Please keep in mind that I知 very new to programming/java, so understand that simple solutions are a lot easier for me to understand and use. I知 trying to allow the user to make a choice between two options. I知 using a scanner to get the next integer they type, assigning it to an int, and then comparing that to another (pre assigned) int. If they match it should display the first (if) outcome, if not, it should display the second (else) outcome. All this works. The problem is that I have to enter two numbers before it replies; only the first number matters though (eg. I press 1 then enter. Nothing happens, so I press 2 then enter and it tells me I choose option 1.) So if anyone can help me stop it from needing two inputs, it would be greatly appreciated.
Here is my code:
import java.util.Scanner; class UserInputsTest { public static void main(String[] args) { System.out.println("Type \"1\" for option 1 and \"2\" for option 2."); //This prints a line asking for user input Scanner scan = new Scanner(System.in); int input = scan.nextInt(); int checkinput = 1; scan.nextInt(); //Creates scanner object and assigns the next integer input value //to int input. if (input == checkinput) { System.out.println("You choose option \"1\"."); } else { System.out.println("You choose option \"2\"."); } //Checks the input obtained from the scanner against int //checkinput, if they match it uses the if outcome, if not it uses //the else outcome. } }