2004ACExamQuestions

2004ACExamQuestions - 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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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 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) 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); (1 mark) b) What is printed by the following? System.out.println(99 / 10 * 10); (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]]); (1 mark) d) What is printed by the following? System.out.println(1 / 4 - 2 * 7 + 5 / 3 - (0 - 8) * 9 + 6); (1 mark) 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)); (1 mark) f) What is printed by the following? System.out.println(Math.sqrt(16) * Math.pow(2, 2)); (1 mark) g) What is printed by the following? String words = {"the", "quick", "brown", "fox"}; System.out.println(words.length + words[1].length()); (1 mark) h) What is printed by the following? String s = "computer"; System.out.println(s.indexOf("pm")); (1 mark) 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"); (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)); (1 mark) 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....
View Full Document

Page1 / 29

2004ACExamQuestions - 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