+ 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.
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.
+ 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!");
}
}
}
+ 2
Thank you all ^^