Java bootcamp · Lab 04

Largest of three

easyIf Else10 minLesson: If Else

Read the question, write Java on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read three integers. Print the largest.

Examples

Example 1
Input
3 9 4
Output
9
Example 2
Input
5 5 2
Output
5
Hint
  1. Math.max(a, Math.max(b, c))
Show correct code

Peek only after you have tried. You can still Check your own version.

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    int b = in.nextInt();
    int c = in.nextInt();
    System.out.println(Math.max(a, Math.max(b, c)));
  }
}
Main.javaJava 21 · javac · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.