java tutorial - Java Math.max() Method - tutorial java - java programming - learn java - java basics - java for beginners



Java numbers max

Learn Java - Java tutorial - Java numbers max - Java examples - Java programs

Description

The Math.max () method returns the maximum of two arguments. The argument can be int, float, long, double.

Syntax

The method has the following options:

double max(double arg1, double arg2)
float max(float arg1, float arg2)
int max(int arg1, int arg2)
long max(long arg1, long arg2)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • The method takes any primitive data type as a parameter.

Return value

  • In Java, Math.max () returns the maximum number of two arguments.

Sample Code

public class Test { 

   public static void main(String args[]) {
      System.out.println(Math.max(1.123, 1.456));      
      System.out.println(Math.max(2.12, 2.0)); 
      System.out.println(Math.max(-5.2, -5.1));
      System.out.println(Math.max(0, -1.1));
   }
}
click below button to copy the code. By - java tutorial - team

Output

1.456
2.12
-5.1
0.0

Related Searches to Java Math.max() Method