ICSE Class 10 Computer Applications Question 8 of 14

Mathematical Library Methods — Question 8

Back to all questions
8
Question

Question 8

Write a program in Java to find the maximum of three numbers using Math.max() method.

Answer
import java.util.Scanner;

public class KboatGreatestNumber
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter First Number: ");
        int a = in.nextInt();
        System.out.print("Enter Second Number: ");
        int b = in.nextInt();
        System.out.print("Enter Third Number: ");
        int c = in.nextInt();
        
        int g = Math.max(a, b);
        g = Math.max(g, c);
        
        System.out.println("Greatest Number = " + g);
    }
}
Output
BlueJ output of KboatGreatestNumber.java