0

adding string condition to if statements?

String name= "Winston"; int age =22; int height=180; if (age==22&&height==180) {System.out.print("welcome";} else System.out.print("incorrect";} how do I add a condition where name needs to be "Winston" too for it to print "welcome"? thanks.

24th Sep 2016, 8:57 PM
Felix Robinson
Felix Robinson - avatar
4 Réponses
+ 1
I think because its not a math operation you need name.equals() method to check a string.
25th Sep 2016, 12:23 AM
Callum Butcher
Callum Butcher - avatar
0
System.out.print("welcome winston");
24th Sep 2016, 9:14 PM
Has Xan
Has Xan - avatar
0
no, I mean what do I add in if (age==22&&height==180)? I tried (name=="Winston"&&age==22&&height==180), there was no errors, but it output was always incorrect.
24th Sep 2016, 9:21 PM
Felix Robinson
Felix Robinson - avatar
0
name. equals() works thanks!
25th Sep 2016, 1:16 AM
Felix Robinson
Felix Robinson - avatar