The MAX()
function returns the largest value from the two numbers sent as a parameter.
Figure 1 shows a visual representation of the MAX()
function.
type max(type num-1, type num-2)
The MAX()
function takes the two numbers as a parameter.
The numbers can be
int
,double
,float
, orlong
.
The MAX()
function returns the largest value from the two numbers sent as a parameter.
class JAVA {public static void main( String args[] ) {// two positive numbersSystem.out.println("Maximum between 9 and 8:");System.out.println(Math.max(9,8));//one positive and the other negativeSystem.out.println("Maximum between -9 and 8:");System.out.println(Math.max(-9,8));// both negative numbersSystem.out.println("Maximum between -9 and -10:");System.out.println(Math.max(-9,-10));// both double numbersSystem.out.println("Maximum between 12.234 and 1.2345:");System.out.println(Math.max(12.234,1.2345));// one int and the other doubleSystem.out.println("Maximum between 12.234 and 1:");System.out.println(Math.max(12.234,1));}}