+ 2
Nested If Statements | Java
I get output as âSuspendedâ instead other nested âifâ commands Can u help me? https://code.sololearn.com/cZ5mo5FgP4UR/?ref=app
6 RĂ©ponses
+ 7
hotto doggu
At line 10, you wrote,
if(isSuspended = true)
= Is an assignment operator.
That's why, even if you take false as an input isSuspended is assigned to true and hence the output Suspended.
[ Same goes for line 16 ]
https://code.sololearn.com/chHGpdJ52PVh/?ref=app
+ 1
I see, it worked! Thank you so much Minho đ°đ·
+ 1
You're welcome, hotto doggu
0
I guess you added âelseâ
and i made but it did not work
Professional Coder
0
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){
if(ourScore > theirScore) {
System.out.println("Won");}
}
if (ourScore == theirScore) {
System.out.println("Draw");
}
if (ourScore < theirScore) {
System.out.println("Lost");
}
}
}