2009S2ExamQuestions

2009S2ExamQuestions - CompSci 101 CONTINUED THE UNIVERSITY...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CompSci 101 CONTINUED THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2009 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this exam. 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) Q1 (/12) Q4 (/10) Q7 (/6) Q10 (/10) Q2 (/8) Q5 (/10) Q8 (/7) Q11 (/10) Q3 (/10) Q6 (/10) Q9 (/7) Total /100 Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... CONTINUED Question 1 (12 marks) a) What is the output when the following code is executed? System.out.println(4 + 5 + " cats " + 3 + 5 * 2); (2 marks) b) What is the output when the following code is executed.? boolean a = true; boolean b = false; int x = 20; System.out.println((x > (x / 5) * (x / 10)) && (a || !b)); (2 marks) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... CONTINUED Question 1 (12 marks) a) What is the output when the following code is executed? System.out.println(4 + 5 + " cats " + 3 + 5 * 2); (2 marks) b) What is the output when the following code is executed.? boolean a = true; boolean b = false; int x = 20; System.out.println((x > (x / 5) * (x / 10)) && (a || !b)); (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... CONTINUED c) Complete the output when the following code is executed. String name1 = new String("Winnie the Pooh"); String name2 = "Pooh"; String name3 = name1.substring(name1.length() - 4); System. out .println("1: " + (name3 == name2)); System. out .println("2: " + (name3.equals(name2))); 1: 2: (2 marks) d) Complete the conditions in the following if-else-if-statement so the code produces the intended output: System.out.print("Enter your grade (A, B, C or D): "); String x = Keyboard.readInput(); if ( ) { System.out.println("Wow an A grade student!"); } else if ( ) { System.out.println("Sorry, D is not a pass"); } else { System.out.println("You passed OK."); } (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... CONTINUED e) What does the following code output for an array, x, of six integers? Assume that the array has been declared and constructed, but that no other operations have been performed on the array before the code executes. x[1] = 9; x[3] = 5; x[4] = 8; System.out.println(x[x.length - 2] + x[1]); (2 marks) f) Complete the output when the following code is executed. int myArray1 = {3, 5, 3, 6, 8}; int myArray2; myArray2 = new int[myArray1.length]; for (int i = myArray1.length - 1; i >= 0; i--) { myArray2[i] = myArray1[i]; } myArray2[4] = 9; System.out.println("1: " + myArray1[4]); System.out.println("2: " + myArray2[3]); 1: 2: (2 marks)...
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 / 27

2009S2ExamQuestions - CompSci 101 CONTINUED THE UNIVERSITY...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online