public class array {
public static void main(String[] args) {
System.out.println("Start");
//
System.out.println("------------------------");
int x[] = new int[5];
System.out.println("x.length - " + x.length);
//
System.out.println("------------------------");
int y[] = {1,2,3,4,5};
System.out.println("y.length - " + y.length);
//
System.out.println("------------------------");
int z1[] = new int[3];
z1[0] = 1;
z1[1] = 2;
z1[2] = 3;
int z2[] = new int[3];
//同一のインスタンスを参照する事になる
z2 = z1;
System.out.println("z2[0] -> " + z2[0]);
System.out.println("z2[1] -> " + z2[1]);
System.out.println("z2[2] -> " + z2[2]);
z1[0] = 10;
z1[1] = 20;
z1[2] = 30;
System.out.println("代入後");
System.out.println("z1[0] -> " + z1[0]);
System.out.println("z1[1] -> " + z1[1]);
System.out.println("z1[2] -> " + z1[2]);
System.out.println("z2[0] -> " + z2[0]);
System.out.println("z2[1] -> " + z2[1]);
System.out.println("z2[2] -> " + z2[2]);
System.out.println("End");
}
}
|