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");} } }
6 ответов
+ 2
IsSuspende=true it is assignment, you must use ==
+ 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");
}
}
}
0
Thank you!
0
// or
if ( IsSuspended ) {
0
Thank you Zemiak. It works too 👍🏼👍🏼
- 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.