+ 1

Why won't this code run?

public class Password { public static void main(String[] args) { int I = 12; if int I = 12; System.out.println("Hello!"); else System.out.println("Nope"); } }

10th Mar 2017, 1:52 PM
One Puncher
One Puncher - avatar
4 odpowiedzi
+ 3
int I = 12; //assingn the value to variable l if (l ==12){//compare the value of variable l //do something if l value == 12 System.out.println("Hello!"); }else{ //do something else System.out.println("Nope"); }
10th Mar 2017, 2:10 PM
seamiki
seamiki - avatar
+ 2
use == instead of = while checking the condition and use parenthesis as explained in other comments
10th Mar 2017, 2:10 PM
POJO
POJO - avatar
0
It still won't work, it keeps saying int is not an Rvalue
10th Mar 2017, 2:06 PM
One Puncher
One Puncher - avatar
0
once you define I and an int, you just call it I after than, you are trying to define it a second time and it already exists. int I = 12; define I==12; call int I==12; define again, throw error
10th Mar 2017, 5:39 PM
LordHill
LordHill - avatar