2009S1TestAnswers

2009S1TestAnswers - 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

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 THE UNIVERSITY OF AUCKLAND CONTINUED FIRST SEMESTER, 2009 Campus: City TEST COMPUTER SCIENCE 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: Q1 (/40) Q4 (/6) Q7 (/6) Q2 (/9) Q5 (/5) Q8 (/8) Q3 (/10) Q6 (/6) Q9 (/10) TOTAL (/100) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... CONTINUED Question 1 (40 marks) a) What is the output produced by the following code? int a = 2 + 1 * 7 - 4 / 5 * 8 + 1; System.out.println(a); 10 (2 marks) b) What is the output produced by the following code? String a = 1 + 2 + "3 + 4" + 5 + 6; System.out.println(a); 33 + 456 (2 marks) c) What is the output produced by the following code? System.out.println("A\"\nB\\n\"n"); A" B\n"n (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... CONTINUED d) What is the output produced by the following code? String message1 = new String("OH HAPPY DAYS"); String message2 = message1.substring(1, 5); System.out.println(message2); H HA (2 marks) e) What is the output produced by the following code? String word = new String("SUPERWOMAN"); int pos1 = word.indexOf("PER"); int pos2 = word.indexOf("T"); System.out.println(pos1 + " " + pos2); 2 -1 (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... CONTINUED f) What is the output produced by the following code? String words = new String("LUCKY YOU"); char c1 = words.charAt(0); words = words.substring(6); words = words + c1; System.out.println(words); YOUL (2 marks) g) The following statement assigns a random number to the variable, a . What are ALL the possible values which can be assigned to the variable, a ? int a = (int) (Math.random() * 3) + 5; 5, 6, 7 (2 marks) h) What is the output produced by the following code? int a = Math.max(Math.max(4, 5), Math.min(6, 7)); System.out.println(a); 6 (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................... CONTINUED i) What is the output produced by the following code? int a = 5; int b = 6; int c = b; a = c + 1; b = a + 2; c = b + 3; System.out.println(a + ", " + b + ", " + c); 7, 9, 12 (2 marks) j) What is the output produced by the following code? String digits = "14"; System.out.println(3 + digits); System.out.println(1 + Integer.parseInt(digits)); 314 15 (2 marks) k) What is the output of the following code?...
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 / 18

2009S1TestAnswers - 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