Home » Java programming language

Java Math Class static double max(double d1,double d2) with example

Java Math Class static double max(double d1,double d2) method: Here, we are going to learn about the static double max(double d1,double d2) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 05, 2019

Math Class static double max(double d1,double d2)

  • This method is available in java.lang package.
  • This method is used to return the maximum one of both the given arguments in the method or in other words it returns the largest value of the given two arguments.
  • This is a static method so it is accessible with the class name too.
  • The return type of this method is double, it returns the largest element from the given two arguments (which are of double types).
  • In this method, we pass two double values parameters as an argument.
  • This method does not throw any exception.

Syntax:

    public static double max(double d1, double d2){
    }

Parameter(s): double d1, double d2 – two double values, in which we have to find the largest value.

Return value:

The return type of this method is double, it returns the largest/maximum value.

Note:

  • If we pass "NaN", it returns "NaN".
  • If we pass the same value as both parameters, it returns the same value.

Java program to demonstrate example of max(double d1, double d2) method

// Java program to demonstrate the example of 
// max(double d1, double d2) method of Math Class

public class MaxDoubleTypeMethod {
    public static void main(String[] args) {
        // declaring the variables
        double d1 = -0.0;
        double d2 = 0.0;
        double d3 = -0.6;
        double d4 = 124.68;

        // displaying the values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // Here , we will get (0.0) because we are 
        // passing parameter whose value is (-0.0,0.0)
        System.out.println("Math.max(d1,d2): " + Math.max(d1, d2));

        // Here , we will get (124.68) and we are 
        // passing parameter whose value is (0.0,124.68)
        System.out.println("Math.max(d2,d4): " + Math.max(d2, d4));
    }
}

Output

E:\Programs>javac MaxDoubleTypeMethod.java

E:\Programs>java MaxDoubleTypeMethod
d1: -0.0
d2: 0.0
d3: -0.6
d4: 124.68
Math.max(d1,d2): 0.0
Math.max(d2,d4): 124.68





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.