+ 1

Can someone tell me why this is not working please?

I know this is a very basic code but I couldn't figure out how to make the input part sooo if someone can help me I will be thankful https://code.sololearn.com/cI4dTAL2tjKX/?ref=app

1st Nov 2017, 9:07 PM
Mert
Mert - avatar
4 Answers
+ 9
you must specalize the type of your variable, that is String in your case, and in if conditions you must use == for comparison or better for String equals method
1st Nov 2017, 9:17 PM
Vukan
Vukan - avatar
+ 2
Thank you all I corrected it thanks for your help !
1st Nov 2017, 9:44 PM
Mert
Mert - avatar
+ 1
import java.util.Scanner; class MyClass { public static void main(String[ ] args) { System.out.println("are you from the planet earth"); Scanner scn = new Scanner(System.in); String answer = scn.nextLine(); switch(answer){ case "yes": System.out.println("Niceee"); break; case "no": System.out.println("?????"); break; default: System.out.println("Please write proper answer"); } } } I hope this helped you.
1st Nov 2017, 9:34 PM
Aleksandar Krstic
Aleksandar Krstic - avatar