代码如下
[AppleScript] 纯文本查看 复制代码
public class Tr_2 {
public static void main(String[] args) {
int[][] arr = {{1,2,3},{2,2,3},{3,0,4,3}};
int[] array = new int[arr.length];
int max = 0;
int index =0;
for (int i = 0;i<array.length;i++) {
array[i] = 0;
for (int j = 0;j < arr[i].length;j++) {
array[i] += arr[i][j];
}
if(max < array[i]) {
max = array[i];
index = i;
}
}
StringBuffer sb = new StringBuffer(" 一维数组:{");
for (int i = 0; i < arr[index].length; i++) {
if(i==arr[index].length-1) {
sb.append(arr[index][i]).append("}");
}else {
sb.append(arr[index][i]).append(",");
}
}
System.out.println("最大值:"+ max + sb.toString());
}
} |