Write a function (java static method) that computes the maximum of two integer.
maxOfTwo(1, 2) → 2
maxOfTwo(2, 1) → 2
maxOfTwo(1, 1) → 1
**(to start use):
public int maxOfTwo(int a, int b) {
And then complete the function (java static method)MaxOfThree so that it returns the maximum (highest) of the three int values passed as the parameters.
maxOfThree(1, 2, 3) → 3
maxOfThree(0, 2, 1) → 2
maxOfThree(88, 4, 5) → 88
**(to start use):
public int maxOfThree(int a, int b, int c) {
public class Max { public int maxOfTwo(int a, int b) { if (a > b) return a; else return b; } public int maxOfThree(int a, int b, int c) { return maxOfTwo(maxOfTwo(a, b), c); } public static void main(String[] args) { System.out.println(new Max().maxOfTwo(1, 2)); System.out.println(new Max().maxOfTwo(2, 1)); System.out.println(new Max().maxOfTwo(1, 1)); System.out.println(new Max().maxOfThree(1, 2, 3)); System.out.println(new Max().maxOfThree(0, 2, 1)); System.out.println(new Max().maxOfThree(88, 4, 5)); } }
Get Answers For Free
Most questions answered within 1 hours.