Largest of Three
Completed
Read three integers and print the largest using if statements (not Math.max).
Input
Three integers.
Output
The largest.
Example
Input
3 9 4
Output
9
Editor
Java
Hints
Assume the first is the largest, then compare the others.
Solution explanation
Keeping a running maximum scales to any number of values.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
System.out.println(max);
}
}