0

Can anybody help me with this code with nested loops?

Hi everybody, I'm trying to solved the match case and almost got it. According to SoloLearn, i've got the solution for 4/5 test cases. I can't think of what the 5. test case could be. I appreciate your help! 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 && ourScore > theirScore){ System.out.println("Suspended"); } else { if (ourScore < theirScore) System.out.println("Lost"); if (ourScore == theirScore) System.out.println("Draw"); if (ourScore > theirScore) System.out.println("Won"); } } }

19th Jan 2021, 10:51 AM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
5 ответов
+ 2
Binh Tan Nguyen Don't check ourScore > theirScore with if condition. Just check if (isSuspended) { } else { }
19th Jan 2021, 10:58 AM
A͢J
A͢J - avatar
+ 1
Thank you so much I Am AJ! I thought it was necessary to write a boolean expression in the if-statement. Now I know, that I don't 👍
19th Jan 2021, 11:00 AM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
+ 1
Binh Tan Nguyen Second thing boolean variable returns true or false so no need to write isSuspended == true or isSuspended == false. You can simply write if(isSuspended) { } Or if(!isSuspended) { }
19th Jan 2021, 11:04 AM
A͢J
A͢J - avatar
+ 1
I Am AJ! Thanks for the information. Appreciate it! 😁
19th Jan 2021, 11:06 AM
Binh Tan Nguyen
Binh Tan Nguyen - avatar
0
See in condition, use "==" instead of "=".
19th Jan 2021, 11:00 AM
Ritesh Patel
Ritesh Patel - avatar