Code doesn't output Suspended but outputs Won when the user inputs true. Can someone help explain what have I done wrong with this code, please?
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
boolean isSuspended = read.nextBoolean();
int ourScore = read.nextInt();
int theirScore = read.nextInt();
if(isSuspended = true){
if(ourScore > theirScore){
System.out.println("Won");
} if(ourScore < theirScore){
System.out.println("Lost");
} if(ourScore == theirScore){
System.out.println("Draw");
}
} else {
System.out.println("Suspended");
}
}
}
You use
=incorrectly. In your example,if(isSuspended = true) {}means:To not assigned but check, you should use
==instead.or better:
P.S. I think you also mixed up the if cases.