I would simplify this by introducing a variable max:

public static int max(int a, int b, int c, int d) {

    int max = a;

    if (b > max)
        max = b;
    if (c > max)
        max = c;
    if (d > max)
        max = d;

     return max;
}

You could also use Math.max, as suggested by fast snail, but since this seems to be homework, I would prefer the algorithmic solution.

Math.max(Math.max(a,b),Math.max(c,d))
Answer from Patrick Hofman on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-min-method-examples
Java Math min() method with Examples - GeeksforGeeks
January 9, 2026 - The value with the greater negative magnitude is considered smaller. Hence, -25 is returned as it is less than -23. If Math.min() is used frequently, you can statically import the method to avoid repeated class qualification. ... import static java.lang.Math.min; class GFG { public static void main(String[] args) { int a = 3; int b = 4; System.out.println(min(a, b)); } }
🌐
W3Schools
w3schools.com › java › ref_math_min.asp
Java Math min() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate · ❮ Math Methods · Get the lowest value from different pairs of numbers: ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › min
Java Math min() - Get Minimum Value | Vultr Docs
September 27, 2024 - Even if the numbers are the same, Math.min() effectively handles this by returning the value itself, as both are the minimum.
🌐
Quora
quora.com › Can-Math-min-have-only-two-parameters-in-Java
Can Math.min have only two parameters in Java? - Quora
Answer (1 of 2): Sometimes I don’t know wether the guys asking the questions here are lazy, stupid, trolls or just plain blank. Look at Math (Java Platform SE 7 ) You will find that Math.min() has 4 implementations, each only hold 2 arguments. If ...
🌐
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.
🌐
Programiz
programiz.com › java-programming › library › math › min
Java Math min()
returns the minimum value among the specified arguments · class Main { public static void main(String[] args) { // Math.min() with int arguments int num1 = 35; int num2 = 88; System.out.println(Math.min(num1, num2)); // 35 // Math.min() with long arguments long num3 = 64532L; long num4 = 252324L; System.out.println(Math.min(num3, num4)); // 64532 // Math.min() with float arguments float num5 = 4.5f; float num6 = 9.67f; System.out.println(Math.min(num5, num6)); // 4.5 // Math.min() with double arguments double num7 = 23.44d; double num8 = 32.11d; System.out.println(Math.min(num7, num8)); // 23.44 } } In the above example, we have used the Math.min() method with int, long, float, and double type arguments.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-min-method
Java Math.min() Method
public static int min(int a, int b): Compares the passed integer numbers and returns the smaller integer number. This method has total four variations in the Math class, to compare different data types such as float, long and double.
🌐
Scaler
scaler.com › home › topics › min() in java
min() in Java - Scaler Topics
April 8, 2024 - The outcome will be the same if ... in java can be of the following types: int( for ex: 2,6,81), double (for ex: 22.4, 3.5), float( for ex: 2.65f, 7.89f), and long(for ex: 10l, 2l)....
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! :)

🌐
Javatpoint
javatpoint.com › java-math-min-method
Java Math.min() method with Examples - Javatpoint
Java Math.min() method with Examples on abs(), min(), max(), avg(), round(), ceil(), floor(), pow(), sqrt(), sin(), cos(), tan(), exp() etc.
🌐
JavaBeat
javabeat.net › home › how to use math.min() method in java?
How to Use Math.min() Method in Java?
November 30, 2023 - To use the “Math.min()” method in Java, pass two variables from which the minimum value needs to be found as arguments and the method returns the smallest value argument. If one of the operand values is negative, then the negative value will be returned and it can be worked with all primitive data types like int, float, double, and long.
🌐
Oracle
forums.oracle.com › ords › apexds › post › finding-the-minimum-of-4-numbers-not-using-an-array-0116
Finding the minimum of 4 numbers, NOT using an array? - Oracle Forums
October 9, 2008 - I wan't to be able to do something like this Math.min(w,x,y,z) so i can find the smallest value of 4 numbers.
🌐
iO Flood
ioflood.com › blog › math-min-java
Using Math.min in Java: A Detailed Tutorial
February 29, 2024 - Check for NaN values: Before passing values to Math.min(), ensure they’re valid numbers. If there’s a chance of encountering NaN values, add checks to handle them. Remember that negative numbers are smaller than positive numbers: When dealing with negative numbers, remember that they’re considered smaller than all positive numbers. Ensure consistent data types: When comparing numbers of different data types, Java will automatically convert the smaller data type to the larger one, which can lead to unexpected results.
🌐
TutorialKart
tutorialkart.com › java › java-math › java-math-min
Java Math.min() - Minimum Value
November 23, 2020 - If you provide arguments of different datatype, then the lower datatype is promoted to higher datatype, and smallest value with the respective datatype is returned. ... public class MathExample { public static void main(String[] args) { int a = 5; float b = 10.2F; float result = Math.min(a, b); System.out.println(result); } } ... In this example, among int and float, float is higher datatype and hence, a is promoted to float. min(int, float) becomes min(float, float). In this Java Tutorial, we learned about Java Math.min() function, with example programs.
🌐
Tutorial Gateway
tutorialgateway.org › java-min-function
Java min Function
March 22, 2025 - In this example, we use the Math.min function to find the Minimum or Smaller value from a different set of data types and display the output. First, we used it directly on both positive and negative integer values. The first three statements will call the integer type static int min(integer a, integer b) method and find the smallest among the values. Next, We used the Java Math.min Function on variables b, c, d, and e (they belong to double type).
🌐
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! ... Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.