# 2008SSExamAnswers - COMPSCI 101 THE UNIVERSITY OF AUCKLAND...

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

COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2008 Campus: City COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) NOTE: Attempt ALL questions Write your answers in the space provided There is space at the back for answers that overflow the allotted space No calculators are permitted Surname: Forenames: Student ID number: Login name: Q1 (/20) Q4 (/6) Q7 (/6) Q10 (/8) Q2 (/8) Q5 (/6) Q8 (/8) Q11 (/10) Q3 (/8) Q6 (/10) Q9 (/10) TOTAL (/100)

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

View Full Document
- 2 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED Question 1 (20 marks) a) What is the output of the following code? System.out.println(2 + 9 + "3" + 5 + (2 + 4)); 11356 (2 marks) b) What is the output of the following code? System.out.println(Math.max(3,5) + Math.min(4,9)); 9 (2 marks) c) Write a Java boolean expression which tests whether the String identified by the variable, name , is less than 10 characters long and contains the letter ‘ r ’. name.length() < 10 && name.indexOf('r') > -1 (2 marks)
- 3 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED d) Complete the output of the following code. Rectangle a = new Rectangle(0, 1, 2, 3); Rectangle b = new Rectangle(10, 20, 30, 40); Rectangle c; c = b; b = new Rectangle(10, 20, 30, 40); System.out.println("1. " + a.equals(b)); System.out.println("2. " + (a == b)); System.out.println("3. " + a.equals(c)); System.out.println("4. " + (a == c)); System.out.println("5. " + b.equals(c)); System.out.println("6. " + (b == c)); 1. false 2. false 3. false 4. false 5. true 6. false (2 marks) e) What is printed by the following? int a = 5; int b = 10; if ((a < b) && !(b < 10)) { System.out.println("A"); } else { System.out.println("B"); } A (2 marks)

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

View Full Document
- 4 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED f) The positive() method is called in the following way: boolean[] bs = {true, true, false, false}; double nums = positive(bs, "10"); Complete the method header for the positive() method (i.e. complete the first line of the method definition). private double positive ( boolean[] nums, String a ) { int x = Integer.parseInt(a); double d = 0.0; for (int i = 0; i < x; i++) { if (nums[i]) { d = d + 5; } } return d; } (2 marks) g) What is the output of the following code? String a = "100"; System.out.println(a + 1); System.out.println(Integer.parseInt(a) + 1); 1001 101 (2 marks)
- 5 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED h) What is printed by the following code segment?

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

View Full Document
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 / 26

2008SSExamAnswers - COMPSCI 101 THE UNIVERSITY OF AUCKLAND...

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

View Full Document
Ask a homework question - tutors are online