【发布时间】:2016-08-24 14:33:53
【问题描述】:
我正在编写一个函数,它检索二维数组中每一行的最大值,并返回一个一维数组,其中每个索引都相对于二维数组的列行索引。
例如,如果我有一个二维数组:
{1,2,3}
{4,5,6}
{7,8,9}
它应该返回一个数组
{3,6,9}
到目前为止,这是我的代码:
double[] rowMaxes(double[][] nums) {
double [] count = new double [nums.length];
for(int i = 0; i < count.length; i++){
for(int x = 0; x < nums[0].length; x++){
for(int n = 0; n < nums.length; n++){
if(nums[x][n] > count[i]){
count[i] = nums[x][n];
}
}
}
}
return count;
}
【问题讨论】:
-
请参考我的Java 8 one liner解决方案
标签: java arrays multidimensional-array compiler-errors max