I am trying to allow user to key in two inputs and check user have key in both value or not but it come out error. here is example code
public static void add train{
int a,b;
System.out.println("Enter train ID");
System.out.println("(**Example '1001'**)");
b=sc.nextInt();
System.out.println("1. to Night Safari");
System.out.println("2. to River Safari");
System.out.println("3. to Zoo Main Entrance ");
System.out.println("Enter a destination for the train");
a= sc.nextInt();
}
this is my previous code for getting input from user, and now I need to book train ticket
public static void book(){
System.out.println("Where do you want to go?");
System.out.println("1. to Night Safari");
System.out.println("2. to River Safari");
System.out.println("3. to Zoo Main Entrance ");
a=sc.nextInt();
if (a==1 && b !=null){//incomparable types: int and <nulltype>
System.out.println("Valid");
}
else if (a==2 && b !=null){
System.out.println("Valid");
}
//and more
else{
System.out.println("Invalid");
}
}
because user can key in optional so I need to check the train is exist in order to process booking Is something wrong with my code or just this is impossible to be done in Java?