+ 1

Whats the problem? Cannot convert int to boolean. Code below.

int choose; System.out.println("Choose:1 or 2 or 3"); Scanner chooseScan=new Scanner(System.in); choose=chooseScan.nextInt; if(choose=1){ System.out.println("pig"); } if (choose==2){ System.out.println("goat"); }else{System.out.println("write 1/2")}

2nd Nov 2016, 8:02 PM
Adam
Adam - avatar
9 Answers
+ 1
you are assigning value to variable, not comparing.
2nd Nov 2016, 8:06 PM
Nick V. Kondratiev
Nick V. Kondratiev - avatar
+ 1
it must be choose==1
2nd Nov 2016, 8:09 PM
Ven Zallow
Ven Zallow - avatar
+ 1
please edit your post to your updated code so i can see the error and help
2nd Nov 2016, 8:23 PM
Ven Zallow
Ven Zallow - avatar
+ 1
you have 2 seperate if statements here is how your code works: u printed 1 first if statements checks choose variable whose value is 1 so it prints "pig" then it comes to second if statement and it checks choose variable, its 1 not 2 so its executes else statement and print "write 1/2" u should use else if statement if (choose==1){ System.out.println("pig"); }else if (choose==2){ System.out.println("goat"); }else{System.out.println("write 1/2")}
2nd Nov 2016, 8:42 PM
Ven Zallow
Ven Zallow - avatar
+ 1
oo i see i forgot this. you get 👍 thanks
2nd Nov 2016, 8:46 PM
Adam
Adam - avatar
+ 1
👍
2nd Nov 2016, 8:49 PM
Ven Zallow
Ven Zallow - avatar
0
thank you. after two more if comes else. i write in 1/2/3 but i get the messge of the else statement too
2nd Nov 2016, 8:19 PM
Adam
Adam - avatar
0
and why?
2nd Nov 2016, 8:21 PM
Adam
Adam - avatar
0
ive edited it
2nd Nov 2016, 8:29 PM
Adam
Adam - avatar