2005S1ExamQuestions

2005S1ExamQuestions - VERSION 1 COMPSCI 101 THE UNIVERSITY...

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

View Full Document Right Arrow Icon
VERSION 1 COMPSCI 101 THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2005 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) Surname . ............................................................................................. Forenames . .......................................................................................... Student ID . .......................................................................................... Login name(UPI) . ............................................................................... NOTE: Attempt ALL questions Answer the multiple choice questions in section A by circling the correct answer Write the answer to the questions in section B in the space provided Examiner to complete: Question Mark 1 – 20 (/40) 21 (/8) 22 (/10) 23 (/12) 24 (/5) 25 (/10) 26 (/10) 27 (/5) Total . (/100) CONTINUED
Background image of page 1

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

View Full DocumentRight Arrow Icon
SECTION A: MULTIPLE CHOICE QUESTIONS Each question in this section is worth 2 marks. Circle the letter corresponding to your choice. There is only one correct answer for each question. 1. What is the output produced by the following code? System.out.println("1 + 2" + 3) ; (a) 6 (b) 123 (c) 1 + 2 + 3 (d) 1 + 23 (e) 3 + 3 2. What is the output produced by the following code? System.out.println(3 / 2 * 5 % 3); (a) 2 (b) 3 (c) 0 (d) 1 (e) None of the above 3. Which of the following is the correct way to declare a symbolic constant? (a) int final size = 10; (b) final int size = 10; (c) int final SIZE = 10; (d) final int SIZE = 10; (e) int size = 10;
Background image of page 2
VERSION 1 - 3 - COMPSCI 101 Question/Answer Sheet ID. ....................................... 4. Which one of the identifiers shown below follows the style convention for naming classes? (a) countNumbers (b) Print_Alphabet (c) Spaceinvaders (d) JellyBeans (e) myfirstprogram 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 = 1; i < 10; i = i + 2) { System.out.print("A"); } (e) System.out.print("output: "); for (int i = 5; i > 1; i--) { System.out.print("A"); } CONTINUED
Background image of page 3

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

View Full DocumentRight Arrow Icon
VERSION 1 - 4 - COMPSCI 101 Question/Answer Sheet ID. ....................................... 6. Given the methods declared below, which statement would result in the value 10 being printed to the screen? private int bar(int i) { return i * 2; } private int foo(int i) { return i + 2; } (a) System.out.println(bar(4)); (b) System.out.println(foo(bar(4))); (c) System.out.println(foo(4)); (d) System.out.println(bar(foo(4))); (e) System.out.println(foo(4) + bar(4)); 7. What is the output produced by the following code? int a = 3; int b = 7; if (a > b) { if (a < b) { System.out.print(“X”); } else { System.out.print(“Y”); } } else { System.out.println(“Z”); } (a) X (b) Y (c) Z (d) YZ (e) XZ CONTINUED
Background image of page 4
VERSION 1 - 5 - COMPSCI 101 Question/Answer Sheet ID. ....................................... 8. Which declaration of variables will ensure that the boolean expression: (a || b) && (a && !c) evaluates to true ? (a) boolean a = false, b = true, c = true; (b) boolean a = false, b = false, c = false; (c) boolean a = true, b = true, c = true; (d) boolean a = false, b = true, c = false; (e) boolean a = true, b = false, c = false; 9. What is the output produced by the following code? String word1 = "FANTASTIC"; char c1; int number = 0; int counter = word1.length() - 1; while (counter > 0) { c1 = word1.charAt(counter); if (c1 == 'T') { counter = counter - 2; } else { counter = counter - 1; number++; } } System.out.println("output: " + number); (a) output: 5 (b) output: 6 (c) output: 8 (d) output: 4 (e) output: 7 CONTINUED
Background image of page 5

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

View Full DocumentRight Arrow Icon
VERSION 1 - 6 - COMPSCI 101 Question/Answer Sheet ID. .......................................
Background image of page 6
Image of page 7
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 / 32

2005S1ExamQuestions - VERSION 1 COMPSCI 101 THE UNIVERSITY...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online