for(int i = 0;i < arr.length;i++){
for(int j = 0; j < arr[i].length;j++){
sout(arr[i][j]);
}
sout();
}
数组练习2
public class ArrayExer1 {
public static void main(String[] args) {
int arr[][] = new int[][]{
{
3,5,8},{
12,9},{
7,0,6,4}};
int sum = 0;
for (int i = 0;i < arr.length;i++){
for(int j = 0;j < arr[i].length;j++) {
sum += arr[i][j];
}
}
System.out.println("所有元素的总和为:" + sum);
}
}
练习3
package array;
public class YangHuiTest {
public static void main(String[] args) {
int[][] yangHui = new int[10][];
for (int i =0;i<yangHui.length;i++){
yangHui[i] = new int[i + 1];
yangHui[i][0] = 1;
yangHui[i][i] = 1;
for (int j = 1; j < yangHui[i].length - 1