2007S1TestQuestions

2007S1TestQuestions - VERSION ONE COMPSCI 101 THE...

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

View Full Document Right Arrow Icon
VERSION ONE COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED FIRST SEMESTER, 2007 Campus: City T E S T COMPUTER SCIENCE Principles of Programming (Time Allowed: ONE hour and FIFTEEN minutes) NOTE: Attempt ALL questions. Answer the multiple choice questions in section A by circling the correct answer on the answer booklet. Write the answers to the questions in section B in the space provided on the answer booklet. Calculators are NOT permitted. SECTION A: MULTIPLE CHOICE QUESTIONS Each question in this section is worth 2 marks. Circle the letter corresponding to your choice on the attached answer sheet. There is only one correct answer for each question. 1. What is the output produced by the following code? System.out.println( 3 * (5 - 1) + 4 - 3 * 2 + 1 ); (a) 11 (b) 15 (c) 27 (d) 9 (e) none of the above
Background image of page 1

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

View Full DocumentRight Arrow Icon
VERSION ONE - 2 - COMPSCI 101 Question Booklet CONTINUED 2. What is the output produced by the following code? System.out.println( 3 + 4 * 2 + "" + 10 / 5 + 3 + 1 ); (a) 17 (b) 38231 (c) 11231 (d) 116 (e) none of the above 3. What is the output produced by the following code? int a = 4; int b = 6; int c = a + 2; b = c; a = b - 3; c = c + 1; System.out.println("a: " + a + ", b: " + b + ", c: " + c); (a) a: 4, b: 6, c: 6 (b) a: 3, b: 6, c: 7 (c) a: 4, b: 5, c: 7 (d) a: 3, b: 5, c: 6 (e) none of the above
Background image of page 2
VERSION ONE - 3 - COMPSCI 101 Question Booklet CONTINUED 4. What is the output produced by the following code? int a = 4; int b = 6; int c = 5; int d = Math.max(Math.min(a,b),Math.min(a,Math.min(c,b))); System.out.println("d: " + d); (a) d: 6 (b) d: 5 (c) d: 4 (d) d: 9 (e) none of the above 5. What is the smallest possible number which is printed by the following code? int a = (int)(Math.random() * 4 + 1); int b = (int)(Math.random() * 4 - 1); int c = a + b; System.out.println("c: " + c); (a) c: -1 (b) c: 0 (c) c: 1 (d) c: 2 (e) none of the above
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 ONE - 4 - COMPSCI 101 Question Booklet CONTINUED 6. Which of the following could NOT have been printed by the following code? int a = (int)(Math.random() * 5) + 2; int b = (int)(Math.random() * 2) - 1; int c = a + b; System.out.println("c: " + c); (a) c: 1 (b) c: 2 (c) c: 5 (d) c: 7 (e) none of the above 7. What is the output produced by the following code? double b = 5.6; int a = (int)b; b = a/2; System.out.println("a: " + a + ", b: " + b); (a) a: 5, b: 2.5 (b) a: 5, b: 2.0 (c) a: 5.6, b: 2.5 (d) a: 6.0, b: 3.0 (e) none of the above
Background image of page 4
VERSION ONE - 5 - COMPSCI 101 Question Booklet CONTINUED 8. What is the output produced by the following code? int a = 10 % 12; int b = 10 % 4; System.out.println("a: " + a + ", b: " + b); (a) a: 0, b: 2 (b) a: 10, b: 4 (c) a: 10, b: 2 (d) a: 2, b: 2 (e) none of the above 9. What is the output produced by the following code if the user enters the number 2 when prompted?
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 17

2007S1TestQuestions - VERSION ONE COMPSCI 101 THE...

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

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