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.


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.


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.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *