# 2011S2TestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

This preview shows pages 1–7. Sign up to view the full content.

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)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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); 7 * 11 (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: 3 b: 25 (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: 8 (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: 27 num3: 0.0 (2 marks)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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: 12 2: -1 (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? C (2 marks) b) What is the output if the variable, value , is assigned 0? C (2 marks) c) What is the output if the variable, value , is assigned 25? E (2 marks)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question/Answer Sheet - Page 6 - CompSci 101 ID: . ..........................................................
This is the end of the preview. Sign up to access the rest of the 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 / 26

2011S2TestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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

View Full Document
Ask a homework question - tutors are online