例如這種int[][]={{12,2,3,4},{3,5,6},{4,8}}如何輸出數組{12,6,8}
ArrayList<int> list = new ArrayList<int>();
for (int i = 0; i < arr.length(); i++)
{
int max = arr[i][0];
for (int j = 1; j < arr[i].length(); j++)
{
if (max < arr[i][j]) max = arr[i][j];
}
list.add(max);
}
int[] result = new int[list.length()];
for (int i = 0; i < list.length(); i++) result[i] = list.get(i);
手寫的