2008SSExamQuestions

# 2008SSExamQuestions - COMPSCI 101 THE UNIVERSITY OF...

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)); (2 marks) b) What is the output of the following code? System.out.println(Math.max(3,5) + Math.min(4,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 ’. (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. 2. 3. 4. 5. 6. (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"); } (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 positive ( ) { 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); (2 marks)
- 5 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED h) What is printed by the following code segment? String[] s = { "zero", "one", "two" }; s[2] = s[1]; s[1] = s[0]; for(int i = 0; i < s.length; i++) { System.out.print(s[i] + " "); } (2 marks) i) Write a Java statement which declares and constructs an array of 30 Rectangle objects. The array should be called boxes .

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.

{[ snackBarMessage ]}

### Page1 / 26

2008SSExamQuestions - COMPSCI 101 THE UNIVERSITY OF...

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

View Full Document
Ask a homework question - tutors are online