Java Basic Examples

Find Maximum number using max method of Math class in Java

This Java example shows how to find maximum of two numbers using max() method of Java Math class.

How to find maximum of two numbers using Math class?

Use max() static method of Java Math class to find maximum of two numbers.

This method returns maximum of two integer numbers.

max() method has been overloaded for double, float and long data types so that same method can be used for double, float and long types.

Output

How to find the maximum number of 3 or more numbers?

max() method of Math class accepts only two arguments. So directly, maximum of 3 numbers cannot be found using max method. However, we can find the max of 3 numbers like below given example.

Output

Please let us know your views in the comments section below.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.

Tags