0

Nested if Statements... Win, Lose or Draw

import java.util.Scanner; 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(); // your code goes here if (isSuspended = true) { System.out.println("Suspended"); } else { System.out.println("False"); } if(ourScore > theirScore){System.out.println("Won");} if(ourScore == theirScore){System.out.println("Draw");} if(ourScore < theirScore){System.out.println("Lost");} } }

4th Apr 2021, 3:15 PM
Chin Eu
Chin Eu - avatar
6 Respuestas
+ 2
IsSuspende=true it is assignment, you must use ==
4th Apr 2021, 3:29 PM
Евгений Демидов
Евгений Демидов - avatar
+ 1
This is the code i used and worked. import java.util.Scanner; 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(); // your code goes here if(isSuspended==true) { System.out.println("Suspended"); } if(isSuspended==false && ourScore>theirScore) { System.out.println("Won"); } else if(isSuspended==false && theirScore>ourScore) { System.out.println("Lost"); } else if(ourScore==theirScore) { System.out.println("Draw"); } } }
20th Sep 2021, 3:14 PM
Brian Nash
0
Thank you!
4th Apr 2021, 3:52 PM
Chin Eu
Chin Eu - avatar
0
// or if ( IsSuspended ) {
4th Apr 2021, 10:29 PM
zemiak
0
Thank you Zemiak. It works too 👍🏼👍🏼
5th Apr 2021, 10:45 AM
Chin Eu
Chin Eu - avatar
- 1
Please help with my code above. Can’t seem to get the correct output if “False” is the input. Don’t really get how Boolean works.
4th Apr 2021, 3:17 PM
Chin Eu
Chin Eu - avatar