+ 6

How can i use user input to ckeck something? If(){} else {}

Why it Shows illegal start of an Expression? What ist the mistake? https://code.sololearn.com/crOn39NTTu4w/?ref=app Thanks for helping me.

27th Oct 2018, 1:25 PM
A.I.E
A.I.E - avatar
3 Réponses
+ 8
Why to use three time equal to sign? To compare two values or variables, use two equal to signs. import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int myVar = sc.nextInt(); if (myVar /* input */ == 18) { System.out.println("Too Young"); } else { System.out.println("Welcome!"); } } } this will work.
27th Oct 2018, 1:45 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 6
you have to use double equal sign instead of three, and you can try this to take user input: class MyClass { public static void main(String[ ] args) { Scanner m = new Scanner(System.in); int myVar = m.nextInt(); if (myVar /* input */ == 18) { System.out.println("Too Young"); } else { System.out.println("Welcome!"); } } }
27th Oct 2018, 1:49 PM
Shruti
Shruti - avatar
+ 2
Thank you all ^^
27th Oct 2018, 2:07 PM
A.I.E
A.I.E - avatar