Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

max()

Example

Retrieve the maximum value from various pairs of numbers.

System.out.println(Math.max(2.0, 0.25));
System.out.println(Math.max(31.2f, 18.0f));
System.out.println(Math.max(14, 22));
System.out.println(Math.max(96L, 2048L));

Definition and Usage

The max() method retrieves the number with the highest value from a pair of numbers.

Tip: To obtain the number with the lowest value, you can utilize the min() method.

Syntax

One of the following:

public static double max(double x, double y) 
public static float max(float x, float y) 
public static int max(int x, int y) 
public static long max(longx, long y) 

Parameter Values

Parameter

Description

x

Mandatory. A numerical value is expected.

y

Mandatory. A numerical value is expected.

Technical Details

Returns:

A double, float, int, or long value representing the larger of two numbers.

Java Version:

Any