max(): This method is available in the Math class of Java.
Syntax:
int java.lang.Math.max(int a, int b)
This method takes two arguments of type int as its argument. This method returns the greater of two int values. That is, the result is the argument closer to the value of Integer.MAX_VALUE.
Note:
1. If the arguments have the same value, the result is that same value.
Parameters: Two parameters are required for this method.
a: an argument.
b: another argument.
Returns: the larger of a and b.
For Exaxmple:
Math.max(10,7) = > It returns 10
Approach
Java
public class MaxInt {public static void main(String[] args) {int a = 10, b = 7;System.out.println(Math.max(a, b));}}
Output:
10
No comments:
Post a Comment