2006SSTestAnswers

2006SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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

View Full Document Right Arrow Icon
CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2006 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time allowed: 75 MINUTES) 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:
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 CompSci 101 Test Results Question Marks Out of Question 1 (output) 20 Question 2 (methods) 7 Question 3 (methods) 7 Question 4 (arrays) 10 Question 5 (classes) 10 Question 6 (code tracing) 6 TOTAL 60
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (20 marks) a) What is printed by the following? System.out.println("\\\\nnnn"); \\nnnn (2 marks) b) What is printed by the following? System.out.println("1" + (2+3)); 15 (2 marks) c) What is printed by the following? int value = 13; boolean result1 = (value > 54) || !(value < 0); boolean result2 = (value != 12 ) && (value%2 != 0); System.out.println("result1 " + result1); System.out.println("result2 " + result2); result1 true result2 true (2 marks)
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 d) What is printed by the following? int[] numbers = {4, 2, -7, 5, 1, 6, 3}; int index = numbers[6] + numbers[numbers[4]]; System.out.println(numbers[numbers[index]]); 3 (2 marks) e) What is printed by the following? String word = "STARRY"; int position1 = word.indexOf('R'); int position2 = word.indexOf("AS"); System.out.println("position1 " + position1); System.out.println("position2 " + position2); position1 3 position2 -1 (2 marks) f) What is printed by the following? String name = "Computer Science"; String result = name.substring(3, 5) + name.substring(13); System.out.println(result); punce (2 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED g) What is printed by the following? int value = 6; if (value < 4) { System.out.println("Line 1"); value = 7; } if (value > 6) { System.out.println("Line 2"); value = -1; } else if (value < 1) { System.out.println("Line 3"); } else { System.out.println("Line 4"); } System.out.println("Line 5"); Line 4 Line 5 (2 marks) h) What is printed by the following?
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 / 17

2006SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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