2004ACExamAnswers

2004ACExamAnswers - CompSci 101 SS C THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 SS C THE UNIVERSITY OF AUCKLAND CONTINUED Summer Semester, 2004 City Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO HOURS) Surname: Forenames: Student ID number: Login name (UPI): INSTRUCTIONS: Attempt ALL questions Write your answers in the space provided There is space at the back for answers that overflow the allotted space Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 (/10) 7 (/10) 2 (/10) 8 (/8) 3 (/8) 9 (/8) 4 (/8) 10 (/8) 5 (/10) 11 (/10) 6 (/10) TOTAL: (/100)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) a) What is printed by the following? System.out.println(5 + 5 + 5 + "+" + 5 + 5); 15+55 (1 mark) b) What is printed by the following? System.out.println(99 / 10 * 10); 90 (1 mark) c) What is printed by the following? int[] nums = {1, 2, 3, 4, 5, 6}; System.out.println(nums[nums.length - nums[0]]); 6 (1 mark) d) What is printed by the following? System.out.println(1 / 4 - 2 * 7 + 5 / 3 - (0 - 8) * 9 + 6); 65 (1 mark)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED e) What is printed by the following? String word = new String("success"); System.out.println(word.substring(3)); cess (1 mark) f) What is printed by the following? System.out.println(Math.sqrt(16) * Math.pow(2, 2)); 16.0 (1 mark) g) What is printed by the following? String[] words = {"the", "quick", "brown", "fox"}; System.out.println(words.length + words[1].length()); 9 (1 mark) h) What is printed by the following? String s = "computer"; System.out.println(s.indexOf("pm")); -1 (1 mark)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED i) What is printed by the following? System.out.println("\\n\"nn\nn"); \n"nn n (1 mark) j) What is printed by the following? Rectangle a = new Rectangle(10, 100, 20, 30); Rectangle b = new Rectangle(25, 10, 5, 100); System.out.println(a.intersects(b)); true (1 mark)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (10 marks) The following program, Q2 , is supposed to calculate and display to the screen the total length of all of the words in the phrase: " to be or not to be ". These words have been stored in an array, and a method called sumLengths() has been defined to calculate the total length of these words.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 28

2004ACExamAnswers - CompSci 101 SS C THE UNIVERSITY OF...

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

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