Y is the if condition not getting exceuted in this java code..its jumping off to the else statement. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Y is the if condition not getting exceuted in this java code..its jumping off to the else statement.

In this code, if the user inputs "java".. The code should execute the if statement.. but even if the user inputs " java" in this code..it executes the else statement.. pls help.#bug https://code.sololearn.com/cb6BP2AVt59Q/?ref=app

15th Jun 2017, 4:57 AM
suryapoojary
suryapoojary - avatar
4 Answers
+ 2
a.equals("java") == will check to see if they are the same String object not the same String value.
15th Jun 2017, 5:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
== does not compare the actual values
15th Jun 2017, 5:06 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 4
thanks a ton guys ...fixed it!!!..I'm lovin java..
15th Jun 2017, 5:09 AM
suryapoojary
suryapoojary - avatar
+ 3
u cant compare strings with an == operator so use 'equals' operation to compare strings
15th Jun 2017, 5:02 AM
Suhail Pappu
Suhail Pappu - avatar