+ 1

You are an administrator at a football club who must categorize already played games ... Why is my code not working?

My code works. But not with the input true, 2, 1. What do I have to do so that all tests run? Here is my code: 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(); if (ourScore > theirScore) { System.out.println("Won"); } else if (isSuspended) { System.out.println("Suspended"); } else if (ourScore < theirScore) { System.out.println("Lost"); } else { System.out.println("Draw"); } } } Thank you.

16th Aug 2021, 11:14 AM
Lisa Kraack
Lisa Kraack - avatar
4 Respuestas
+ 2
Lisa Kraack , you are mixing everything in the conditions. Try something like => if (isSuspended) { System.out.println("Suspended") ; } else{ //here you can place all your checks for the result }
16th Aug 2021, 11:55 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Okay. Thank you very much for your help.
16th Aug 2021, 12:00 PM
Lisa Kraack
Lisa Kraack - avatar
0
Lisa Kraack , post full description of the task and also input and expected output.
16th Aug 2021, 11:32 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
You are an administrator at a football club who must categorize already played games on the team's website. The given program takes 3 inputs: 1. match status - which checks if the match is suspended ("true") or not suspended ("false") 2. your team's score 3. opposing team's score. Complete the program so that if the match is suspended (the 1st input is "true"), it will output "Suspended". If the match is not suspended ( the1st output is false), the following statuses should be set depending on the match result: "Won", "Lost" and "Draw". Input: true 2 1 Your Output: Won Expected Output: Suspended
16th Aug 2021, 11:36 AM
Lisa Kraack
Lisa Kraack - avatar