public interface DoubleGenerator { public double NextDouble(); }
Problem 2) (30 points)
Write down the output generated by the following code segment.
private void init1(Point[] A) { for (int i=0;i < A.length;i++) A[i] = new Point(i,i*i); } private void init2(Point[] A) { for (int i=0;i < A.length;i++) { A[i].x = i; A[i].y = 3*i; } } private void show(Point[] A, int n) { System.out.println("n = "+n+" ---"); for (int i=0;i < A.length;i++) System.out.println(" "+i +": "+A[i].x+" "+A[i].y); } ... Point[] A = new Point[4]; Point[] B = new Point[5]; Point[] C = new Point[6]; Point[] D = new Point[4]; init1(A); show(A,1); init2(A); show(A,2); init1(B); B[2].x = 7; B[2].y = 11; show(B,3); init2(B); show(B,4); init1(C); C[2] = C[4]; show(C,5); init2(C); show(C,6); A = C; show(A,7); init2(A); show(A,8); show(C,9); init2(D); show(D,10);