Java – Math max() Example, Math max() Program

Math class is part of java.lang package. Math max method returns the bigger highest value of two double numbers with fraction. If value is negative, it will return highest value nearest to positive value. max function return type is double. Max method find highest bigger value between 2 number and compare two value to get bigger number.

Math max example explains how to use Math max function in java.

public class JavaMathMaxExample {

    public static void main(String[] args) {

        double E1 = Math.max(34.45, 23.67);

        double E2 = Math.max(14.45, 23.67);

        double E3 = Math.max(-14.45, -23.67);

        System.out.println("Math max value :"+E1);
        System.out.println("Math max value :"+E2);
        System.out.println("Math max value :"+E3);
    }
}

Output

Math max value :34.45
Math max value :23.67
Math max value :-14.45

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post