+ 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")}
9 Réponses
+ 1
you are assigning value to variable, not comparing.
+ 1
it must be choose==1
+ 1
please edit your post to your updated code so i can see the error and help
+ 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")}
+ 1
oo i see i forgot this. you get 👍 thanks
+ 1
👍
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
0
and why?
0
ive edited it