I'm receiving an error on the following Java code:
public int[] maxEnd3(int[] nums) {
int larger = Math.min(nums[0],nums[2]);
return larger;
}
Error: int larger [] = Math.min(nums[0],nums[2]); ^^^^^^ Type mismatch: cannot convert from int to int[]
Why am I not able to calculate the minimum of 2 array values?
if you want to return the larger in an array then change the return of the method maxEnd3
to int and not array of int..
public int maxEnd3(int[] nums) {
int larger = Math.min(nums[0],nums[2]);
return larger;
}
Your return type is int[], so it is expecting int[] but you are returning a "large" which is an int. Try changing your return type to int or make "large" int[].
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.