+ 1

Hey, does anyone know how to solve this code? Im stuck on it for so long. Thanks in advance

https://code.sololearn.com/ctIMovUJZg5F/?ref=app

4th Sep 2021, 4:29 PM
vizznet
vizznet - avatar
8 odpowiedzi
+ 2
Vizznet Because this condition if(isSuspended = true) is wrong. There should be double equal. Instead of doing that just do this: if (isSuspended) { } No need to compare with true.
4th Sep 2021, 5:27 PM
A͢J
A͢J - avatar
+ 2
import java.lang.Exception; import java.util.Scanner; public class Main { public static void main(String[] args) { try { Scanner read = new Scanner(System.in); boolean isSuspended = read.nextBoolean(); int ourScore = read.nextInt(); int theirScore = read.nextInt(); if(isSuspended) System.out.println("Suspended"); else { if(ourScore > theirScore) System.out.println("Won"); else if(theirScore > ourScore) System.out.println("Lost"); else System.out.println("Draw"); } } catch (Exception e) { System.out.println("Error"); } } } /* Input that: false 10 10 */ // Happy coding and keep learning.
4th Sep 2021, 4:47 PM
SoloProg
SoloProg - avatar
+ 2
Vizznet That 3 parts should be inside else part. If match is suspended then no need to check anything. So you should check everything inside else part.
4th Sep 2021, 4:49 PM
A͢J
A͢J - avatar
+ 1
Vizznet It is very simple. First check suspended then do rest in else part like: if(isSuspended) { System.out.println("Suspended"); } else { //rest condition should be inside this part }
4th Sep 2021, 4:36 PM
A͢J
A͢J - avatar
+ 1
Im sorry but i still dont get it i cant use the else statement because theres 3 parts that have to be checked
4th Sep 2021, 4:46 PM
vizznet
vizznet - avatar
+ 1
Vizznet Whatever I am telling just do that and tell me if I am wrong.
4th Sep 2021, 4:52 PM
A͢J
A͢J - avatar
+ 1
I did it (i think), but it outputs as suspended everytime https://code.sololearn.com/cenyhK72TCxh/?ref=app
4th Sep 2021, 5:00 PM
vizznet
vizznet - avatar
+ 1
Thank you for helping me sir! I understand now
4th Sep 2021, 10:37 PM
vizznet
vizznet - avatar