2009S2TestQuestions

2009S2TestQuestions - CompSci 101 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 THE UNIVERSITY OF AUCKLAND SEMESTER TWO, 2009 Campus: City CompSci 101 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: Lab time: Q1 (/20) Q4 (/10) Q7 (/6) Q2 (/20) Q5 (/18) Q8 (/6) Q3 (/12) Q6 (/8) TOTAL (/100) Question/Answer Sheet - Page 2 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 1 (20 marks) a) What is the output when the following code is executed? int num1 = 4; int num2 = 3; String exp = " a + b "; System.out.println(num1 + num2 + exp + num1 * num2); (2 marks) b) Complete the output when the Q01B program is executed. public class Q01B { public void start() { printAValue(20, 10, 30); } private void printAValue(int num1, int num2, int num3) { int a = Math.max(num1, num2); int b = Math.min(a, num3); System.out.println("Result: " + b); } } Result: (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED c) Complete the output when the following code is executed. String words1 = "super duper"; String words2 = "mish mash"; String words3 = words1.substring(1, 3) + "XX" + words2.substring(4) + "XX"; System.out.println(words3); XX XX (2 marks) d) Complete the output when the following code is executed. String words1 = "WISHY WASHY"; int pos1 = words1.indexOf(" "); int pos2 = words1.indexOf("SH"); int pos3 = words1.indexOf("DISH"); System.out.println("pos1: " + pos1); System.out.println("pos2: " + pos2); System.out.println("pos3: " + pos3); pos1: pos2: pos3: (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED e) Complete the output when the following code is executed. String words1 = "PING PONG"; char a = words1.charAt(3); char b = words1.charAt(5); char c = words1.charAt(8); System.out.println("a: " + a + " b: " + b + " c:" + c); a: b: c: (2 marks) f) Complete the output when the following code is executed. int a = 4; int b = a + 10; int c = a + b; a = a + 4; b = b - a; c = b + a + 1; System.out.println("a: " + a + " b: " + b + " c: " + c); a: b: c: (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 SURNAME: ...................................................... FORENAMES: ..............................................................
View Full Document

Page1 / 22

2009S2TestQuestions - CompSci 101 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