Loading...
Loading...
Loading...
In a college cricket match, Team A and Team B each bat once. Read both scores and print the result line for the scoreboard:
Team A wins by X runs or Team B wins by X runs, where X is the difference in runs;run, not runs;Match tied when the scores are equal.Example 1
Input
182 156
Output
Team A wins by 26 runs
Team A scored 26 more runs.
Example 2
Input
149 150
Output
Team B wins by 1 run
Team B wins by a single run, so the word is run.
Try the problem first. Open one hint at a time.
First decide who won (or if it is a tie) with an else-if ladder.
Inside each winning branch, compute the margin by subtracting the smaller score from the larger one.
Then use a nested if (or the ternary operator) to choose between run and runs.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor