+ 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

7th Dec 2020, 7:24 PM
hotto doggu
hotto doggu - avatar
5 Respostas
+ 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
8th Dec 2020, 1:15 AM
Minho
Minho - avatar
+ 1
I see, it worked! Thank you so much Minho 🇰🇷
8th Dec 2020, 9:55 AM
hotto doggu
hotto doggu - avatar
+ 1
You're welcome, hotto doggu
9th Dec 2020, 4:01 AM
Minho
Minho - avatar
0
I guess you added “else” and i made but it did not work Professional Coder
7th Dec 2020, 7:48 PM
hotto doggu
hotto doggu - avatar
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"); } } }
19th Feb 2022, 8:50 AM
Salman
Salman - avatar