2011S2TestQuestions

2011S2TestQuestions - CompSci 101 THE UNIVERSITY OF...

Info iconThis preview shows pages 1–7. 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 SECOND SEMESTER, 2011 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time Allowed: 75 minutes) NOTE: You must answer all questions in this test. No calculators are permitted Answer in the spaces 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 (/10) Q4 (/9) Q7 (/13) Q10 (/7) Q2 (/8) Q5 (/15) Q8 (/10) Total /100 Q3 (/10) Q6 (/6) Q9 (/12) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... continued Question 1 (10 marks) a) What output is produced when the following code is executed? System.out.println(4 + 3 * (5 / 3) + " * " + (4 - 3) + 1); (2 marks) b) Complete the output produced when the following code is executed. int a = 4; int b = a; a++; b = a; a = a - 2; b = 10 * a - b; System.out.println("a: " + a + " b: " + b); a: b: (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... continued c) Complete the output produced when the following code is executed. int a = 15; int b = 7; int c = a % a; int d = b % (b + 2); int e = a % b; int sum = c + d + e; System.out.println("Sum: " + sum); Sum: (2 marks) d) Complete the output produced when the following code is executed. double num1 = 27.6; int num2 = (int) num1; double num3 = 5 / 10; System.out.println("num2: " + num2); System.out.println("num3: " + num3); num2: num3: (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... continued e) Complete the output produced when the following code is executed. int a = 3; int b = 12; int c = 6; int d = 1; System.out.println("1: " + (c + 2 * a)); System.out.println("2: " + (d - b / c)); 1: 2: (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................... continued Question 2 (8 marks) Parts a), b) and c) refer to the following code. int value = ... if ((value < 10 || value > 30) && !(value == 0)) { System.out.println("A"); } else if (value > 15 && value < 25) { System.out.println("B"); } else if (value < 16) { System.out.println("C"); } else if (value > 25) { System.out.println("D"); } else { System.out.println("E"); } a) What is the output if the variable, value , is assigned 14? (2 marks) b) What is the output if the variable, value , is assigned 0? (2 marks) c) What is the output if the variable, value , is assigned 25? (2 marks) Question/Answer Sheet - Page 6 - CompSci 101 ID: ........................................................... continued d) Write a boolean expression which tests whether the int variable, score , contains a value between 10 and 20 (both inclusive)....
View Full Document

Page1 / 26

2011S2TestQuestions - CompSci 101 THE UNIVERSITY OF...

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

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