Challenge: Biggest of Three

Lab Java Beginner 10 points

Write a method static int maxOfThree(int a, int b, int c) that returns the biggest of three numbers. In main, read three numbers and print the result of your method.

Input

Three whole numbers.

Output

The biggest one.

Example

Input

3 9 4

Output

9
Sample input available Sample output available
Editor
Java

Hints

Start with max = a, then compare with b and c.

Math.max(a, Math.max(b, c)) also works.

Solution explanation

The method keeps the biggest value seen so far and returns it.

Show solution
import java.util.Scanner;

public class Main {
    static int maxOfThree(int a, int b, int c) {
        int max = a;
        if (b > max) max = b;
        if (c > max) max = c;
        return max;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        System.out.println(maxOfThree(a, b, c));
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD