2005S2TestQuestions

2005S2TestQuestions - 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 SECOND SEMESTER, 2005 Campus: City 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 attached answer sheet. Write the answers to the questions in section B in the space provided on the attached answer sheet. Calculators are NOT permitted. SECTION A: MULTIPLE CHOICE QUESTIONS Each question in this section is worth 3 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(1 + "1" + 1); (a) 111 (b) 11 + 1 (c) 21 (d) 12 (e) 1 + 11
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 1 - 2 - COMPSCI 101 Question Sheet CONTINUED 2. What is the output produced by the following code? System.out.println(1.0 / 2); (a) 1 (b) 0.0 (c) 0 (d) 0.5 (e) 1.0 / 2 3. What is the output produced by the following code? System.out.println("\"" + "\\nn"); (a) " n (b) \"\\nn (c) "\ n (d) "\nn (e) \"\ n 4. What is the output produced by the following code? System.out.println( 1 - 6 % 5 + 3 * 4 / 2 - 3 * 3 ); (a) -3 (b) -4 (c) 3 (d) 4 (e) none of the above
Background image of page 2
VERSION 1 - 3 - COMPSCI 101 Question Sheet CONTINUED 5. What is the output produced by the following code? String word = "computer"; System.out.println(word.substring(3, word.length()-2)); (a) u (b) put (c) mput (d) pute (e) mpute 6. What is the output produced by the following code? int a = 1; int b = 2; int c = 3; int w = Math.max(a, b) - Math.min(b, c); int x = Math.max(c, Math.min(a, b)); int y = Math.min(a, Math.max(b, c)); int z = Math.min(Math.max(a, b), Math.max(b, c)); System.out.println(w + " " + x + " " + y + " " + z); (a) 0 3 1 1 (b) 0 2 1 3 (c) 0 3 2 1 (d) 0 1 3 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 1 - 4 - COMPSCI 101 Question Sheet CONTINUED 7. Consider the following method call: String answer = getSomeAnswer(34, "Fish", 13.0); From the list of method headers below, which is the only correct method header which could have been used to define the getSomeAnswer() method? (a) public void start() (b) private String getSomeAnswer(double i, String s, double d) (c) private void getSomeAnswer(int i, String s, double d) (d) private String getSomeAnswer(int i, String s, int d) (e) private String GetSomeAnswer(int i, String s, double d) 8. Which one of the following identifiers is invalid in Java?
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.

Page1 / 14

2005S2TestQuestions - 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