Home >>Java Math Methods >Java Math.max() method
The math.max() method in Java Math is an inbuilt Java method which is used to return Maximum or Largest value from the two arguments given. The arguments in int, float, double, and long are taken up.
public static int max(int a, int b) public static double max(double a, double b) public static long max(long a, long b) public static float max(float a, float b)
a: This is used for first value
b: This parameter is used for second value
This method is used to returns maximum of two numbers.
public class MyClass
{
public static void main(String args[])
{
int a = 15;
int b = 35;
System.out.println(Math.max(a, b));
}
}
public class MyClass
{
public static void main(String args[])
{
double a = 10.06;
double b = -12.12;
System.out.println(Math.max(a, b));
}
}