多次元配列



コード

public class arrary_ {

	public static void main(String[] args) {
		
		System.out.println("Start");
		
		//
		System.out.println("------------------------");
		
		int x[][] = new int[2][3];
		
		System.out.println("x.length -> " + x.length);
		System.out.println("x[0].length -> " + x[0].length);
		System.out.println("x[1].length -> " + x[1].length);

		//
		System.out.println("------------------------");

		int y[][] = {
			{1,   2,   3,   4},
			{10,  20,  30,  40},
			{100, 200, 300, 400}
		};
	
		System.out.println("y.length -> " + y.length);
		System.out.println("y[0].length -> " + y[0].length);
		System.out.println("y[1].length -> " + y[1].length);

		System.out.println("y[0][0] -> " + y[0][0]);
		System.out.println("y[0][1] -> " + y[0][1]);
		System.out.println("y[0][2] -> " + y[0][2]);	
		System.out.println("y[0][3] -> " + y[0][3]);
		
		System.out.println("y[1][0] -> " + y[1][0]);
		System.out.println("y[1][1] -> " + y[1][1]);
		System.out.println("y[1][2] -> " + y[1][2]);	
		System.out.println("y[1][3] -> " + y[1][3]);

		System.out.println("y[2][0] -> " + y[2][0]);
		System.out.println("y[2][1] -> " + y[2][1]);
		System.out.println("y[2][2] -> " + y[2][2]);	
		System.out.println("y[2][3] -> " + y[2][3]);
		
		System.out.println("End");
	}
}
			


結果

Start
------------------------
x.length -> 2
x[0].length -> 3
x[1].length -> 3
------------------------
y.length -> 3
y[0].length -> 4
y[1].length -> 4
y[0][0] -> 1
y[0][1] -> 2
y[0][2] -> 3
y[0][3] -> 4
y[1][0] -> 10
y[1][1] -> 20
y[1][2] -> 30
y[1][3] -> 40
y[2][0] -> 100
y[2][1] -> 200
y[2][2] -> 300
y[2][3] -> 400
End
			

ビジネスPC&PCサーバ


<戻る>

Gポイントポイ活 Amazon Yahoo 楽天

無料ホームページ 楽天モバイル[UNLIMITが今なら1円] 海外格安航空券 海外旅行保険が無料!