

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Learn about the java integer.max() method and how to use it to find the maximum of two integer values with examples. The method returns the greater of two integers passed as arguments.
Typology: Summaries
1 / 3
This page cannot be seen from the preview
Don't miss anything!


In this tutorial, we will learn about Java Integer.max() method, and learn how to use this method to get the maximum of given two integer values, with the help of examples.
Syntax The syntax of max() method with two integers for comparison as parameters is where Parameter Description a The first integer to compare. b The second integer to compare. Returns The method returns value of type int. Example 1 โ max(a, b) : a<b
Java Program
Integer.max( int a, int b)
Output Example 2 โ max(a, b) : a=b
Java Program Output Example 3 โ max(a, b) : a>b
Java Program public class Example { public static void main(String[] args){ int a = 5 ; int b = 7 ; int result = Integer.max(a, b); System.out.println("Result of max("+a+", "+b+") = " + result); } } Result of max(5, 7) = 7 public class Example { public static void main(String[] args){ int a = 5 ; int b = 5 ; int result = Integer.max(a, b); System.out.println("Result of max("+a+", "+b+") = " + result); } } Result of max(5, 5) = 5