Sunday, August 15, 2010

Array: Eggs.java

Courtesy of Sun Web Learning Center

 3. public class Eggs {
 4.   public static void main(String[] args) {    
 5.     int[][] basket1 = new int[2][];
 6.     basket1[0] = new int[3];
 7.     basket1[0] = {1,2,3};
 8.
 9.     int[][] basket2 = new int[2][];
10.     basket2[0] = new int[] {1,2,3};
11.     basket2[0][1] = 7;
12.     System.out.println(basket1[0][1] + " " + basket2[0][1]);
13.   }
14. }


What is the result?

A     1 1
B     2 2
C     1 7
D     2 7
E     Compilation fails
F     An exception is thrown at runtime

E is correct. The assignment on line 7 uses invalid syntax

No comments:

Post a Comment