ADDITIONAL SYSTEM INFORMATION :
suggested code is for all runtimes, all environments.
A DESCRIPTION OF THE PROBLEM :
Currently Math.max(...) and Math.min(...) support two parameters. The looks like below:
public static int max(int a, int b) {
return a > b ? a : b;
}
I suggest it be changed to:
public static int max(int... nums) {
int result = nums[0];
for(int num : nums) {
result = result > num ? result : num;
}
return result;
}
and similar code for Math.min(...).
This will greatly help in coding challenges where min/max needs to be computed of more than 2 numbers, and since this code is backwards compatible, it will not required any changes to old code.
suggested code is for all runtimes, all environments.
A DESCRIPTION OF THE PROBLEM :
Currently Math.max(...) and Math.min(...) support two parameters. The looks like below:
public static int max(int a, int b) {
return a > b ? a : b;
}
I suggest it be changed to:
public static int max(int... nums) {
int result = nums[0];
for(int num : nums) {
result = result > num ? result : num;
}
return result;
}
and similar code for Math.min(...).
This will greatly help in coding challenges where min/max needs to be computed of more than 2 numbers, and since this code is backwards compatible, it will not required any changes to old code.
- duplicates
-
JDK-8199089 varargs method for Math.max(...), min(...), addExact(...), multiplyExact(...) and all commutative and associative operations
-
- Resolved
-