2005S1TestQuestions

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

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

View Full Document Right Arrow Icon
VERSION 1 COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED FIRST SEMESTER, 2005 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: ONE hour and FIFTEEN minutes) 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 No books or calculators are permitted Examiner to complete: Question Mark 1 – 15 (/45) 16 (/20) 17 . (/20) 18 . (/10) 19 . (/5) Total . (/100)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - 2 - COMPSCI 101 ID. ....................................... CONTINUED SECTION A: MULTIPLE CHOICE QUESTIONS Each question in this section is worth 3 marks. Circle the letter corresponding to your choice. There is only one correct answer for each question. 1. Each of the following fragments of Java code use a variable x . Which code fragment is a variable declaration? (a) x = 9; (b) if (x == y) { doSomething(); } (c) int x; (d) System.out.println(x); (e) private int doSomething(int x) { //do something here } 2. Which of the following variable identifiers follows the Java code conventions? (a) sizeOfClass (b) length_of_box (c) HEIGHTOFBOX (d) 2TimesTables (e) circleradius 3. Which of the following identifiers will cause a compile-time error? (a) _abc (b) abc_ (c) 2abc (d) abc2 (e) A_B_C
Background image of page 2
Question/Answer Sheet - 3 - COMPSCI 101 ID. ....................................... CONTINUED 4. What is the output of the following code fragment? int x = 0; int y = 1; int z = 2; x = y; y = z; System.out.println(x + " " + y + " " + z); (a) 0 1 2 (b) 1 1 1 (c) 1 1 2 (d) 1 2 2 (e) 2 2 2 5. Which of the following code fragments will cause a runtime error? (a) int i = 0 / 5; (b) int i = 5.0 / 0; (c) int i = 0 / 5.0; (d) int i = 0; (e) int i = 5 / 0; 6. Which of the following code fragments will compile successfully? (a) int i = 3.5; (b) double d = "3.5"; (c) String s = 3; (d) double d = 3; (e) int i = "3";
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - 4 - COMPSCI 101 ID. ....................................... CONTINUED 7. What is the output produced by the following code fragment? double d = 5 / 10; double e = (double) 5 / 10; double f = (double) (5 / 10); System.out.println(d + " " + e + " " + f); (a) 0.0 0.0 0.0 (b) 0.0 0.0 0.5 (c) 0.0 0.5 0.0 (d) 0.0 0.5 0.5 (e) 0.5 0.5 0.5 8. Which code fragment will ensure that the statement: System.out.println(a == b == c); can be compiled and executed without causing an error? (a)
Background image of page 4
Image of page 5
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

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

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

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