2006SSExamAnswers

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

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2006 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 (/8) Q7 (/12) Q10 (/6) Q2 (/4) Q5 (/8) Q8 (/9) Q11 (/10) Q3 (/5) Q6 (/8) Q9 (/10) TOTAL (/100) - 1 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED Question 1 (20 marks) a) What is printed by the following? System.out.println(40 % 100); 40 (2 marks) b) What is printed by the following? for (int i = 5; i >= 0; i = i-2) { System.out.println(i); } 5 3 1 (2 marks) c) What is printed by the following? int numbers = {1, 2, 3, 4}; System.out.println(numbers[numbers[1]]); 3 (2 marks)- 2 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED d) What is printed by the following? String word1 = new String(" bravo"); String word2 = new String("BRAVO"); String word3 = word2; if ((word1.trim()).equals(word2.toLowerCase())) { System.out.println("1" + word1); } if (word3 == word2) { System.out.println("2" + word2); } 1 bravo 2BRAVO (2 marks) e) What is printed by the following? String name = "Thought is free"; name = name.substring(8); String result = name.substring(3); System.out.println(result); free (2 marks) f) What is printed by the following? String word = "Art is long, life is short"; int position1 = word.indexOf("long"); int position2 = word.indexOf(','); word = word.substring(position1, position2); System.out.println("word: " + word); word: long (2 marks)- 3 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED g) What is printed by the following? Point a = new Point(8, 9); Point b = new Point(8, 9); Point c = a; Point d = new Point(10, 10); System.out.println(a.equals(d)); System.out.println(b == c); System.out.println(c.equals(b)); false false true (2 marks) h) What is printed by the following? boolean result1, result2; int value = 7; result1 = value > 5 && !(value < 0 || value%2 == 1); result2 = (value != 6 && value%2 != 0) || value > 3; System.out.println("result1: " + result1); System.out.println("result2: " + result2); result1: false result2: true (2 marks)- 2 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED d) What is printed by the following? String word1 = new String(" bravo"); String word2 = new String("BRAVO"); String word3 = word2; if ((word1.trim()).equals(word2.toLowerCase())) { System.out.println("1" + word1); } if (word3 == word2) { System.out.println("2" + word2); } 1 bravo 2BRAVO (2 marks) e) What is printed by the following?...
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 / 16

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

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

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