# 2005SSExamAnswers - 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, 2005 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 (/10) Q4 (/10) Q7 (/10) Q10 (/10) Q2 (/10) Q5 (/10) Q8 (/6) Q11 (/12) Q3 (/5) Q6 (/12) Q9 (/5) 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 (10 marks) a) What is printed by the following? System.out.println( 5 + 5 + "5" + 5 + 5 ); 10555 (1 mark) b) What is printed by the following? int a = 5; int b = 2; double d = (double)(a / b); System.out.println( d ); 2.0 (1 mark) c) What is printed by the following? System.out.println( 9 + 3 * (10 % 6) / 2 ); 15 (1 mark) d) What is printed by the following? System.out.println( "n\"n\n\\"+"\"" ); n"n \" (1 mark)
- 3 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED e) What is printed by the following? String[] words = {"cat", "go", "a"}; System.out.println( words[words[1].length()] ); a (1 mark) f) What is printed by the following? Point p = new Point(100, 100); p.translate(101, 99); System.out.println(p.x + " , " + p.y); 201 , 199 (1 mark) g) What is printed by the following? int[] nums = {1,2,3,4,5}; int[] moreNums; moreNums = nums; moreNums[3] = 1000; System.out.println(nums[3]); 1000 (1 mark)

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

View Full Document
- 4 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED h) What is printed by the following? int i = 5; while (i > 0) { i = i - 2; System.out.println(i); } 3 1 -1 (1 mark) i) What is printed by the following? boolean x = false; boolean y = (x && !x) || (x || !x); System.out.println(y); true (1 mark) j) What is printed by the following? int z = Math.max(Math.max(4,5), Math.min(7,6)); System.out.println(z); 6 (1 mark)
- 5 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED Question 2 (10 marks) a) What is the output produced by the following code? String s1 = new String("Happiness"); String s2 = s1.substring(2, 4); System.out.println( s1.indexOf(s2) ); 2 (2 marks) b) What is the output produced by the following code? String s1 = new String("apple"); String s2 = new String("apple"); if( s1.equals(s2) && s2 == s1) System.out.println( "line 1" ); else if( s1.equals(s2) && s2 != s1) System.out.println( "line 2" ); else System.out.println( "line 3" ); line 2 (2 marks) c) What is the output produced by the following code?

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

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