# Getting the maximum of two numbers

The static method max in the math class takes two values and determines the maximum. It can be used for integer, floats, longs and doubles:

```import java.math.*;

public class Main
{
public static void main(String args[]) throws Exception {
int    i1 = 4,     i2 = -10;
long   l1 = 234,   l2 = 235;
float  f1 = 2.2F,  f2 = 2.8F;
double d1 = 12.2D, d2 = 12.8D;

int    maxi = Math.max(i1, i2);
long   maxl = Math.max(l1, l2);
float  maxf = Math.max(f1, f2);
double maxd = Math.max(d1, d2);

System.out.println("Maximum of integers (" + i1 + ", " + i2 + ") = " + maxi);
System.out.println("Maximum of longs    (" + l1 + ", " + l2 + ") = " + maxl);
System.out.println("Maximum of floats   (" + f1 + ", " + f2 + ") = " + maxf);
System.out.println("Maximum of doubles  (" + d1 + ", " + d2 + ") = " + maxd);
}
}
```

outputs:

```Maximum of integers (4, -10) = 4
Maximum of longs    (234, 235) = 235
Maximum of floats   (2.2, 2.8) = 2.8
Maximum of doubles  (12.2, 12.8) = 12.8
```