2010S1ExamQuestions

2010S1ExamQuestions - VERSION 00000001 COMPSCI 101...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: VERSION 00000001 COMPSCI 101 CONTINUED THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2010 Campus: City Computer Science Principles of Programming (Time Allowed: TWO HOURS) SECTION A Question Booklet Note: The use of calculators is NOT permitted. You should separate the Section A Question Booklet from the Section B Question/Answer Booklet. You may keep the Section A Question Booklet. You must hand in the Section B Question/Answer booklet and the Teleform sheet . Compare the Exam version number on the Teleform sheet supplied with the version number above. If they do not match, ask the supervisor for a new sheet. Enter your name and student ID on the Teleform sheet. Your name should be entered left aligned. If your name is longer than the number of boxes provided, truncate it. Answer Section A (multiple-choice questions) on the Teleform answer sheet provided. Each question in this section is worth 2 marks. For Section A, use a dark pencil to mark your answers in the answer boxes on the Teleform sheet. Do not cross out answers on the Teleform sheet if you change your mind. You must completely erase one answer before you choose another one. If you spoil your sheet, ask the supervisor for a replacement. There is one correct answer per question. Answer Section B in the space provided in the Section B Question/Answer Booklet. Attempt all questions. An appendix with a simplified API is included on the last page. VERSION 00000001 - 2 - COMPSCI 101 CONTINUED PLEASE CHECK BEFORE YOU START: Have you entered your name and student ID on the Teleform sheet (letters written in the boxes and corresponding circles filled in) and on the front of the Section B question/answer booklet? There are 20 questions in Section A. Each question is worth 2 marks. Question 1 What is the output of the following code? int a = 5; int b = 10; a = a + b; b = a - b; a = a - b; System.out.println(a + " " + b); (a) 15 5 (b) 5 5 (c) 10 5 (d) 10 10 (e) 5 10 VERSION 00000001 - 3 - COMPSCI 101 CONTINUED Question 2 Consider the following code: String words = {"one", "two", "buckle", "my", "shoe"}; int combinedLength = totalLength(words); System.out.println("Combined length: " + combinedLength); The totalLength() method is passed an array of Strings as a parameter. It returns the sum of the lengths of all the String objects in the array. The output from the code above is: Combined length: 18 Which of the following definitions of the totalLength() method is correct? NOTE: the only difference between the options is whether or not there are () after " length ". (a) private int totalLength(String words) { int total = 0; for (int i = 0; i < words.length(); i++) { total += words[i].length; } return total; } (b) private int totalLength(String words) { int total = 0; for (int i = 0; i < words.length(); i++) { total += words[i].length(); } return total; } (c) private int totalLength(String words) { int total = 0; for (int i = 0; i < words.length; i++) { total += words[i].length(); total += words[i]....
View Full 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 / 38

2010S1ExamQuestions - VERSION 00000001 COMPSCI 101...

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

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