๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 10 โ€บ java-math-min-method
Java Math.min() Method
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)); } }
๐ŸŒ
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!
Find elsewhere
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 โ€บ home โ€บ java/lang โ€บ java math min method
Java Math Min Method
September 1, 2008 - 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.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ lang โ€บ math_min_long.htm
Java - Math min(long x, long y) Method
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.
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ java โ€บ java_ref_math_en.html
Java Math Methods. Lessons for beginners. W3Schools in English
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
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_math.asp
W3Schools.com
Math.min(0, 150, 30, 20, -8, -200); Try it Yourself ยป
๐ŸŒ
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.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ java.lang.math.min
Math.Min Method (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register("min", "(JJ)J", "")>] static member Min : int64 * int64 -> int64 ... Java documentation for java.lang.Math.min(long, long).