How to run scanner first in a if-else statement before execute the rest of the code?
Hi, i would like to create program to let user to choose option 1 or 2 or 3, then depends on the options selected and it might ask user to key in diff info(for example, option 1 ask age, option 2 ask name and etc). But currently the issue is that after user have selected option, it will run the code inside that option(if else statment) before my scanner ( which means my scanner run last). May i know how to solve this issue? public class Program { public static void main(String[] args) { Scanner ans =new Scanner(System.in); System.out.println("Please select 1 or 2 or 3"); String customer_ans = ans.nextLine(); int age; if(customer_ans == "1") { System.out.prinln("Your age:"); age = ans.nextInt() System.out.printf("Your agr is%d", age); } else if(customer_ans == "2") { .... } else { .... } } }