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 OverflowTutorialspoint
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.
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....
Top answer 1 of 5
1
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);
}
2 of 5
0
Java will convert an int to a double when needed. Also, just use Java's Math.max().
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.
Top answer 1 of 4
2
java.lang.Math class provides a max method to find maximum of two double inputs. Here is the signature:
public static double max(double a,
double b)
2 of 4
2
public static double userMax(double[] array) {
double maximum = array[0];
for (double d: array) {
maximum = Math.max(maximum, d);
}
return double;
}
Now after defining this function, you can call:
double toTheMax = userMax(numbers);
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).
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....
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.
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 ·