Loading...
Loading...
Loading...
Three friends play a mobile cricket game and note their scores. Print the highest score.
Write a method static int maxOfTwo(int a, int b) that returns the larger of two numbers. In main, find the top score of three by calling maxOfTwo twice. Do not use Math.max.
Example 1
Input
45 72 38
Output
72
The second player has the top score.
Example 2
Input
90 90 12
Output
90
A tie at the top still prints the score once.
Try the problem first. Open one hint at a time.
The method needs one if: return a when a > b, otherwise return b.
The result of one call can be passed straight into another call: maxOfTwo(maxOfTwo(a, b), c).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor