Home » Java programming language

Java Math Class static float max(float f1,float f2) with example

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

Math Class static float max(float f1,float f2)

  • 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 float, it returns the largest element from the given two arguments (which are of float types).
  • In this method, we pass two float values (float) parameters as an argument.
  • This method does not throw any exception.

Syntax:

    public static float max(float f1, float f2){
    }

Parameter(s): float f1, float f2 – two float values, in which we have to find the largest value.

Return value:

The return type of this method is float, 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(float f1, float f2) method

// Java program to demonstrate the example of 
// max(float f1, float f2) method of Math Class

public class MaxFloatTypeMethod {
    public static void main(String[] args) {
        // declaring variables
        float f1 = -0.0f;
        float f2 = 0.0f;
        float f3 = -0.6f;
        float f4 = 124.58f;

        // displaying the values
        System.out.println("f1: " + f1);
        System.out.println("f2: " + f2);
        System.out.println("f3: " + f3);
        System.out.println("f4: " + f4);

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

        // Here , we will get (124.58) and we are 
        // passing parameter whose value is (0.0f,124.58f)
        System.out.println("Math.max(f2,f4): " + Math.max(f2, f4));
    }
}

Output

E:\Programs>javac MaxFloatTypeMethod.java

E:\Programs>java MaxFloatTypeMethod
f1: -0.0
f2: 0.0
f3: -0.6
f4: 124.58
Math.max(f1,f2): 0.0
Math.max(f2,f4): 124.58





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.