Find maximum of two numbers using Math.max in Java

Description

The following code shows how to find maximum of two numbers using Math.max.

Example


/*from w  w w . ja v  a 2 s.c  o  m*/
public class Main {
  public static void main(String[] args) {
    System.out.println(Math.max(2, 4));
    System.out.println(Math.max(3.4f, 4.3f));
    System.out.println(Math.max(6.34, 1.45));
    System.out.println(Math.max(4l, 5l));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization