2010S2TestAnswers

2010S2TestAnswers - THE UNIVERSITY OF AUCKLAND SECOND...

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

View Full Document Right Arrow Icon
THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2010 Campus: City COMPUTER SCIENCE TEST SOLUTIONS Principles of Programming (Time Allowed: 75 minutes) NOTE: You must answer all questions in this test. No calculators are permitted Answer in the space provided in this booklet. There is space at the back for answers that overflow the allotted space. Surname Forenames Student ID Login (UPI) Lab Time Q1 (/16) Q4 (/8) Q7 (/10) Q2 (/15) Q5 (/10) Q8 (/20) Q3 (/12) Q6 (/9) 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 SURNAME: . ..................................................... FORENAMES: . .......................................................... Question 1 (16 marks) a) What is the output produced by the following code? System.out.println(3 + 2 + " + " + 2 + " * " + 6 + (2 + 1)); 5 + 2 * 63 (2 marks) b) What is the output produced by the following code? System.out.println("A\"nB\nC\\nZ"); A"nB C\nZ (2 marks) c) Complete the output produced by the following code. int num = Math.max(Math.min(Math.max(3, 6), 5), 4); System.out.println("num: " + num); num: 5 (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SURNAME: . ..................................................... FORENAMES: . .......................................................... d) What is the output produced by the following code? String a = new String("Hello World!"); String b = new String(“Hello World!”); System.out.println(a == b); false (2 marks) e) What is the output produced by the following code? int number = 56; if (number % 2 > 0) { System.out.println(“First”); } else { System.out.println(“Second”); } Second (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 SURNAME: . ..................................................... FORENAMES: . .......................................................... f) What is the output produced by the following code? String a = "45"; int x = 1 + (Integer.parseInt(a) / 5 + 2) * 4 ; String b = "" + x; System.out.println(b.equals(a)); true (2 marks) g) Complete the Java statement which assigns a random number which is either 1, 2, 3, 4 or 5 to the int variable, number . int number = (int)(Math.random() * 5 + 1); (2 marks) h) Complete the output when the following code is executed. int a = 6; int b = a + 2; a = b + 2; int c = a; c = c / 5; a = c / 2; System.out.println("a: " + a + " b: " + b + " c: " + c); a: 1 b: 8 c: 2 (2 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 SURNAME: . ..................................................... FORENAMES: . .......................................................... Question 2 (15 marks) a) Complete the output produced by the following code. String phrase = "LITTLE STAR"; String part1 = phrase.substring(4, 6); String part2 = phrase.substring(9); String result = part1 + part2; System.out.println("Result: " + result); Result: LEAR (3 marks) b) Complete the output produced by the following code.
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.

Page1 / 19

2010S2TestAnswers - THE UNIVERSITY OF AUCKLAND SECOND...

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