Java编程入门与应用 P177——例7-8——使用定义方法定义int类型的二维数组,然后初始化二维数组
/**
* Java编程入门与应用 P177——例7-8——使用定义方法定义int类型的二维数组,然后初始化二维数组
*/
public class Defin_two_dimensional_array {
public static void main(String[] args) {
//构造方法1
int[][] temp;
temp = new int[][]{
{1,2},
{3,4}
};
//构造方法2
int[][] temp2 = {{5,6}, {7,8}};
//输出temp的值
System.out.print("temp的值为:");
for(int i = 0; i < temp.length; i++){
for(int j = 0; j < temp[i].length; j++){
System.out.print(temp[i][j] + " ");
}
}
//输出temp2的值
System.out.println();
System.out.print("temp2的值为:");
for(int i = 0; i < temp2.length; i++){
for(int j = 0; j < temp2[i].length; j++){
System.out.print(temp2[i][j] + " ");
}
}
}
}
结果:
temp的值为:1 2 3 4
temp2的值为:5 6 7 8
进程已结束,退出代码为 0
感谢观看
再次感谢~