For int i 0 i blength i bi ai which one of the

This preview shows page 11 - 17 out of 26 pages.

for (int i = 0; i < b.length; i++) { b[i] = a[i]; } Which one of the following lines of code should be used in place of the question marks so that the code above works correctly? (a) int b = new int[a]; (b) int b = new int[a.length]; (c) int[] b = new int[a]; (d) int[] b = new int[a.length]; (e) int b = new int[a[i]];
Image of page 11

Subscribe to view the full document.

VERSION 1 - 12 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED SECTION B 15. The following section of code creates, initialises and modifies an array of Point objects. What would be the output when this code is executed? Point[] pts = new Point[3]; pts[0] = new Point(100, 200); pts[1] = new Point(300, 400); pts[2] = new Point(500, 600); Point temp = pts[1]; pts[1] = pts[2]; pts[0].y = pts[1].x; pts[2].x = pts[0].x; pts[2] = temp; System.out.println(pts[0].x + " , " + pts[0].y); System.out.println(pts[1].x + " , " + pts[1].y); System.out.println(pts[2].x + " , " + pts[2].y); 100 , 500 100 , 600 300 , 400 (6 marks)
Image of page 12