🌐
W3Schools
w3schools.com › java › ref_math_min.asp
Java Math min() Method
System.out.println(Math.min(2.0, 0.25)); System.out.println(Math.min(31.2f, 18.0f)); System.out.println(Math.min(14, 22)); System.out.println(Math.min(96L, 2048L)); ... The min() method returns the number with the lowest value from a pair of numbers.
🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
Strings Concatenation Numbers and Strings Special Characters Code Challenge Java Math Java Booleans
🌐
W3Schools
w3schools.com › java › tryjava.asp
W3Schools online JAVA editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
W3Schools
w3schools.com › java › java_ref_math.asp
Java Math Reference
Strings Concatenation Numbers and Strings Special Characters Code Challenge Java Math Java Booleans
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-min-method-examples
Java Math min() method with Examples - GeeksforGeeks
January 9, 2026 - Therefore, -23 is returned as the minimum value. Math.min() compares two negative values.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_int.htm
Java - Math min(int x, int y) Method
The Java Math min(int a, int b) returns the smaller of two int values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
Programiz
programiz.com › java-programming › library › math › min
Java Math min()
Hence, we are accessing the method ... · Note: The data types of the arguments should be either int, long, float, or double. returns the minimum value among the specified arguments...
🌐
W3Schools
w3schoolsua.github.io › java › java_math_en.html
Java Math. Lessons for beginners. W3Schools in English
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-min-method
Java Math.min() Method
October 9, 2022 - In this tutorial, we will discuss Math.min() method with examples. public class JavaExample { public static void main(String args[]) { float f1 = -2.225f; float f2 = -6.5f; //This will print the smaller float number System.out.println(Math.min(f1, f2)); double d1 = 40000; double d2 = 41000; //This will print the smaller double number System.out.println(Math.min(d1, d2)); } }
Find elsewhere
🌐
W3Schools
w3schools.com › java › ref_math_max.asp
Java Math max() Method
Java Examples Java Videos Java ... number with the highest value from a pair of numbers. Tip: Use the min() method to return the number with the lowest value....
🌐
Codecademy
codecademy.com › docs › java › math methods › .min()
Java | Math Methods | .min() | Codecademy
October 22, 2022 - The Math.min() method returns the minimum value from the given two arguments. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Top answer
1 of 6
22

int

public static int min(int a, int b) {
    return (a <= b) ? a : b;
}

long

public static long min(long a, long b) {
     return (a <= b) ? a : b;
}

float

public static float min(float a, float b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0f) && (b == 0.0f) && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
         return b;
    }
    return (a <= b) ? a : b;
 }

double

public static double min(double a, double b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0d) && (b == 0.0d) && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
        return b;
    }
    return (a <= b) ? a : b;
}

More info: Here

2 of 6
10

Java 7 documentation:

Returns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE. If the arguments have the same value, the result is that same value.

Behaviour:

Math.min(1, 2) => 1
Math.min(1F, 2) => 1F
Math.min(3D, 2F) => 2D
Math.min(-0F, 0F) => -0F
Math.min(0D, -0D) => -0D
Math.min(Float.NaN, -2) => Float.NaN
Math.min(-2F, Double.NaN) => Double.NaN

java.lang.Math and java.lang.StrictMath Source:

public static int min(int a, int b) {
    return (a <= b) ? a : b;
}

java.lang.Math Bytecode (javap -c Math.class of Oracle's JDK's JRE's rt.jar):

public static int min(int, int);
Code:
   0: iload_0           // loads a onto the stack
   1: iload_1           // loads b onto the stack
   2: if_icmpgt     9   // pops two ints (a, b) from the stack
                        // and compares them
                        // if b>a, the jvm continues at label 9
                        // else, at the next instruction, 5
                        // icmpgt is for integer-compare-greater-than
   5: iload_0           // loads a onto the stack
   6: goto          10  // jumps to label 10
   9: iload_1           // loads 
  10: ireturn           // returns the currently loaded integer

If the comparison at 5 is true, a will be loaded, the jvm will jump to 10 and return a, if the comparison yields false, it will jump to 9, which will load and return b.

Intrinsics:

This .hpp file of the Java 8 Hotspot JVM hints that it optimizes Math.min even further with optimized machine code:

do_intrinsic(_min, java_lang_Math, min_name, int2_int_signature, F_S)

This means the above bytecode won't be executed by the Java 8 Hotspot JVM. However, this differs from JVM to JVM, which is why I also explained the bytecode!

Hopefully, now you know all there is to know about Math.min! :)

🌐
Tutorial Gateway
tutorialgateway.org › java-min-function
Java min Function
March 22, 2025 - Next, We used the Function on variables g, h, i, and j (they belong to float type). The next three System.out.println statements will call the float type method ( static float min(float a, float b) ) and find the smallest among the values. Last, We used this Math function on variables k, l, m, and n (they belong to the long type).
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_long.htm
Java - Math min(long x, long y) Method
October 20, 2018 - The Java Math min(long a, long b) returns the smaller of two long values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
CodeGym
codegym.cc › java blog › java math › java math.min() method
Java Math.min() method
September 28, 2023 - At line 8, double min = Math.min(berriesSoldInKg, cherriesSoldInKg); the double “min” stores the lowest of both weights. Later, we compare two doubles (amount in kgs) to check the minimum of the two fruits.
🌐
iO Flood
ioflood.com › blog › math-min-java
Using Math.min in Java: A Detailed Tutorial
February 29, 2024 - When using Math.min(), it’s crucial to ensure that both arguments are of the same data type. If they’re not, Java will automatically convert the smaller data type to the larger one, which can lead to unexpected results.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
4 days ago - If the argument is zero, the result is -Float.MIN_VALUE ... The adjacent floating-point value closer to negative infinity. ... Returns d × 2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set. See the Java Language Specification for a discussion of floating-point value sets.
🌐
W3Schools
w3schoolsua.github.io › java › java_ref_math_en.html
Java Math Methods - W3Schools українською - GitHub Pages
All Math Methods in Java. The Java Math class has many methods that allows you to perform mathematical tasks on numbers. All Math methods are static. Lessons for beginners. W3Schools in English