例如這種int[][]={(12,2,3,4),(3,5,6),(4,8)}如何將最大值及其位置取出
手寫的,你稍微調整下
int[][] arr = {(12,2,3,4),(3,5,6),(4,8)};
int maxi = 0;
int maxj = 0;
for (int i = 0; i < arr.length(); i++)
for (int j = 0; j < arr[i].length(); j++)
{
if (arr[maxi][maxj] < arr[i][j]) { maxi = i; maxj = j; }
}
System.out.println("最大值是" + arr[maxi][maxj] + ",位置是" + maxi + "," + maxj);