{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2008S1ExamAnswersV1 - THE UNIVERSITY OF AUCKLAND FIRST...

This preview shows pages 1–7. Sign up to view the full content.

CONTINUED THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2008 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: Attempt ALL questions. Answer Section A (Multiple choice Questions) on the teleform answer sheet attached. Answer Section B in the spaces provided in this booklet. Calculators are NOT permitted. Surname: Forenames: Student ID number: Login name: Q1 – Q20 Multi-choice (/50) Q23 (/4) Q26 (/6) Q29 (/6) Q21 (/4) Q24 (/6) Q27 (/6) Q22 (/6) Q25 (/6) Q28 (/6) TOTAL (/100)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
VERSION 18832768 - 2 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED SECTION A MULTIPLE CHOICE QUESTIONS Each question in this section is worth 2.5 marks. There is only one correct answer for each question. Select your preferred alternative on the teleform answer sheet provided . 1. What is the output produced by the following code? int a = 4; int b = a; int c = b; a = a + 1; b = b + 2; c = c + 3; b = a; a = b; System.out.println("a: " + a + " b: " + b + " c: " + c); (a) a: 5 b: 5 c: 7 (b) a: 5 b: 5 c: 5 (c) a: 7 b: 7 c: 7 (d) a: 6 b: 5 c: 7 (e) none of the above 2. Which one of the following expressions does NOT evaluate to 2?
VERSION 18832768 - 3 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 3. What is the output of the following statement? int number = 100; while (number % 2 == 0) { System.out.print(number + " "); number = number / 2; } 4. What is the output of the following code? String[] s = new String[3]; s[0] = new String("zero"); s[1] = new String("one"); s[2] = new String("two"); s[1] = s[2]; s[0] = s[1]; s[2] = s[0]; for(int i = 0; i < s.length; i++) { System.out.print(s[i] + " "); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
VERSION 18832768 - 4 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 5. Which one of the five sections of code below does NOT produce the following output: output: AAAA (a) System.out.print("output: "); for (int i = 1; i < 5; i++) { System.out.print("A"); } (b) System.out.print("output: "); for (int i = 1; i < 5 && i != 0; i++) { System.out.print("A"); } (c) System.out.print("output: "); for (int i = 1; i < 5; ) { i = i + 1; System.out.print("A"); } (d) System.out.print("output: "); for (int i = 0; i < 7; i = i + 2) { System.out.print("A"); } (e) System.out.print("output: "); for (int i = 5; i > 0; i--) { System.out.print("A"); } 6. Consider the following boolean expression: (a && b) || (!a) What values would need to be stored in the boolean variables a and b so that this expression evaluates to false ?
VERSION 18832768 - 5 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
VERSION 18832768 - 6 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 7. Which one of the following method calls on the Graphics object would produce the outline of a square, which has a width and height of 50 pixels and which is centred at position (200, 200)? (a) g.drawRect(150, 150, 25, 25); (b) g.drawRect(150, 150, 50, 50); (c) g.drawRect(175, 175, 25, 25); (d) g.drawRect(175, 175, 50, 50); (e) g.drawRect(200, 200, 25, 25);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 32

2008S1ExamAnswersV1 - THE UNIVERSITY OF AUCKLAND FIRST...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online