2008S1ExamQuestionsV1

# 2008S1ExamQuestionsV1 - VERSION 18832768-1 COMPSCI 101 THE...

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

VERSION 18832768 - 1 - COMPSCI 101 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? (a) (int) (1 + 1 + 2 / 4.0 + 2 % (3 - 1)) (b) (int) ((1 + 1 + 2) / 4.0 + 2 % 3 - 1) (c) (int) (1 + 1 + 2 / (4.0 + 2 % 3 - 1)) (d) (int) (1 + 1 + 2 / 4.0 + 2 % 3 - 1) (e) none of the above
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; } (a) 100 (b) 100 50 (c) 100 50 25 (d) 50 (e) 50 25 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] + " "); } (a) one two one (b) one two zero (c) two two two (d) one two two (e) an exception or error will occur when this code is executed

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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

### Page1 / 31

2008S1ExamQuestionsV1 - VERSION 18832768-1 COMPSCI 101 THE...

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

View Full Document
Ask a homework question - tutors are online