Java if statement: How to find if value is not equal null? -
i trying allow user key in 2 inputs , check user have key in both value or not come out error. here 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. night safari"); system.out.println("2. river safari"); system.out.println("3. zoo main entrance "); system.out.println("enter destination train"); a= sc.nextint(); }
this previous code getting input user, , need book train ticket
public static void book(){ system.out.println("where want go?"); system.out.println("1. night safari"); system.out.println("2. river safari"); system.out.println("3. zoo main entrance "); a=sc.nextint(); if (a==1 && b !=null){//incomparable types: int , <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 need check train exist in order process booking wrong code or impossible done in java?
i think you're misunderstanding null
means. null
doesn't refer value, reference (read this answer more info it). bottom line things can reference null
complex types, string
s, integer
s, classes define, etc. primitive types (int
s, boolean
s, etc.) not references, can never reference null
Comments
Post a Comment