KnowledgeBoat Logo

Computer Applications

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

Java

Java Math Lib Methods

37 Likes

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 Write a program in Java to find the maximum of three numbers using Math.max() method.

Answered By

16 Likes


Related Questions