java代码输出二维数组


下午做作业,碰到一个java二维数组的题,结果我就犯2了,愣是没看清数组的个数,导致敲了一遍代码才看出来。

public class Xiti8 {
	public static void main(String[] args) {
		double a[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
		double b[][] = { { 1.0, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } };

		boolean boo = (a[0] == b[0]);
		System.out.println(boo);

		boo = (a[0][0] == b[0][0]);
		System.out.println(boo);

		a[0] = b[0];
		a[1] = b[1];

		System.out.println(a == b);
		System.out.println("a.length = " + a.length);

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}
}

输出结果:
false
true
false
a.length = 3
1.0 2.2 3.3 4.4
5.5 6.6 7.7 8.8
7.0 8.0 9.0

发表评论