如果您考虑一下,如果要查找最高值,则必须检查所有值.没有办法解决这个问题(除非对数组进行排序,这很简单 - 只需要取每个数组的最后一个(或者先排序),然后选择最大的数组.例:
int highest = array1[i]; // note: don't do this if the array could be empty
for(int i = 0; i < array1.length; i++) {
if(highest<array1[i]) highest = array1[i];
}
for(int i = 0; i < array2.length; i++) {
if(highest<array2[i]) highest = array2[i];
}
// highest is now the highest
Run Code Online (Sandbox Code Playgroud)