You can use Math.max(double a, double b) and Math.max(int a, int b)

Example:

public static int max(int x, int y) {
    return Math.max(x, y);
}
public static double max(double num1, double num2) { 
    return Math.max(num1, num2);
}
public static double max(double num1, double num2, double num3) {
    return Math.max(Math.max(num1, num2), num3);
}
Answer from Freddy on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math.max() method
Java - Math max(double x, double y) Method
September 1, 2008 - The Java Math max(double a, double b) returns the greater of two double values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-max-method
Java Math max() Method - GeeksforGeeks
May 14, 2025 - Example 1: In this example, we will see the basic usage of Math.max() method with Double values. ... // Java program to demonstrate // the use of max() function // when two double data-type // numbers are passed as arguments import java.lang.Math; public class Geeks { public static void main(String args[]) { double a = 12.123; double b = 12.456; // prints the maximum of two numbers System.out.println(Math.max(a, b)); } }
🌐
Scaler
scaler.com › home › topics › max function in java
Max Function in Java - Scaler Topics
April 20, 2024 - The return type of this method is double because both parameters are of double datatype. ... The 3.5 is the maximum among 2.0 and 3.5 values and hence, Math.max() method picks that value.
🌐
LabEx
labex.io › tutorials › java-java-double-max-method-117623
Mastering the Java Double Max Method | LabEx
Inside the main method, we have declared two variables x and y of double data type and assigned the values 34.5 and -20.1, respectively. We then printed the maximum value between x and y using the Double.max() method. Save the changes to the MaxDouble.java file and exit the code editor.
🌐
CodeGym
codegym.cc › java blog › java math › java math max() method
Java Math.max() method with Examples
December 5, 2024 - Finding the maximum value between the two double values. public class Main { public static void main(String args[]) { double x = 15.68; double y = -37.47; System.out.println(Math.max(x, y)); } } The output will be 15.68 Finding the maximum value ...
🌐
W3Schools
w3schools.com › java › ref_math_max.asp
Java Math max() Method
System.out.println(Math.max(2.0, ....println(Math.max(96L, 2048L)); Try it Yourself » · The max() method returns the number with the highest value from a pair of numbers....
🌐
Javatpoint
javatpoint.com › java-double-max-method
Java Double max() Method - Javatpoint
The max() method of Java Double class returns the double object having greater value amongst two double values. The result returned is same as by invoking Math.max() method.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math.max
Math.Max Method (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register("max", "(DD)D", "")>] static member Max : double * double -> double · a · Double · an argument. b · Double · another argument. Double · the larger of a and b. Attributes · RegisterAttribute · Java documentation for java.lang.Math.max(double, double).
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › max
Java Math max() - Find Maximum Value | Vultr Docs
December 3, 2024 - Use the Math.max() method to find the maximum value. java Copy · double x = 5.5; double y = 3.3; double maximum = Math.max(x, y); System.out.println("The maximum value is: " + maximum); Explain Code · In this snippet, Math.max() evaluates ...
🌐
Codecademy
codecademy.com › docs › java › math methods › .max()
Java | Math Methods | .max() | Codecademy
October 22, 2022 - Learn to code in Java — a robust ... hours ... The .max() method takes two parameters num1 and num2. num1 and num2 can be of type int, float, double or long....
🌐
JavaBeat
javabeat.net › home › how to use the math.max() function in java?
How to Use the Math.max() Function in Java?
January 23, 2024 - In Java, the Math.max() function accepts two numbers as arguments, performs comparison, and retrieves the maximum number. ... The “datatype” can be long, double, float, or int.
🌐
iO Flood
ioflood.com › blog › math-max-java
Math.max() Java Function | Usage, Syntax, and Examples
February 29, 2024 - While the basic use of the Math.max() function is limited to two numbers, its application can be extended to handle more complex scenarios, such as finding the maximum in an array or a collection. This can be achieved by using the function in a loop or in conjunction with other Java features.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math.max() method
Java Math.max() Method
September 1, 2008 - The java.lang.Math.max(int a, int b) returns the greater of two int values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value.
🌐
Tutorial Gateway
tutorialgateway.org › java-max-function
Java max Function
March 28, 2025 - The following three statements will call the method of double type ( static double max(double a, double b) ) and find the largest among the values. Next, We used it on variables g, h, i, and j (they belong to the float type).
🌐
Programiz
programiz.com › java-programming › library › math › max
Java Math max()
In the above example, we have used the Math.max() method with int, long, float, and double type arguments.
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-max-method
Java Math.max() Method
public class JavaExample { public static void main(String args[]) { float num = -15.5f; float num2 = -5.55f; //This will print the greater float number System.out.println(Math.max(num, num2)); double d1 = 1001.22; double d2 = 2500.33; //This will print the greater double number System.out....
🌐
Javatpoint
javatpoint.com › java-math-max-method
Java Math.max() method with Examples - Javatpoint
Java program to delete a new node from the middle of the doubly linked list · Java program to find the maximum and minimum value node from a doubly linked list · Java program to insert a new node at the beginning of the Doubly Linked list · Java program to insert a new node at the end of the Doubly Linked List ·