2012SSTestAnswers

2012SSTestAnswers - CompSci 101 CONTINUED 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 CONTINUED THE UNIVERSITY OF AUCKLAND SUMMER SEMESTER, 2012 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 space provided in this booklet. There is space at the back for answers that overflow the allotted space. Surname Forenames Student ID Login (UPI) Lab Times Q1 Ann (/10) Q4 Ann (/16) Q7 Adriana (/10) Q2 Adriana (/12) Q5 Adriana (/20) Total /100 Q3 Alastair (/12) Q6 Alastair (/20) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... CONTINUED Question 1 (10 marks) a) What is the output produced by the following code? System.out.println(3 + 5 + " + " + 2 + " + " + 8 + ("2" + 1) + 3); 8 + 2 + 8213 (2 marks) b) What is the output produced by the following code? System.out.println("An\"B\\n\"N"); An"B\n"N (2 marks) c) Complete the output produced by the following code. int num; num = Math.min(Math.max(Math.min(3, 6), Math.min(21, 5)), Math.max(3,4)); System.out.println("num: " + num); num: 4 (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... CONTINUED d) Complete the output produced by the following code: int a = 3; int b = 4; int c = a + b; b = c - b; a = a + c; c = c + 2; System.out.println("a: " + a + " b: " + b + " c: " + c); a: 10 b: 3 c: 9 (2 marks) e) Complete the output produced by the following code: int a = 2 + 7 % 3; int b = 8 % 11; double c = 15 / 4; System.out.println("a: " + a + " b: " + b + " c: " + c); a: 3 b: 8 c: 3.0 (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... CONTINUED Question 2 (12 marks) a) Complete the output produced by the following code: int number = 9; boolean result = ! ( ! (number < 0) && ! (number >= 3)); System.out.println("result: " + result); result: true (2 marks) b) What is the output produced by the following code? int value1 = 8; int value2 = 6; System.out.print("A "); if (value1 > value2 + 2) { System.out.print("B "); value2 = value1 + 2; } else if (value2 > value1 - 3) { System.out.print("C "); if(value1 < 8) { System.out.print("D "); } else { value1++; } value2 = value2 / 2; } System.out.println(value1 + " " + value2); A C 9 3 (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................... CONTINUED c) What is the output produced by the following code? int value1 = 8; int value2 = 6; System.out.print("A "); if (value1 < value2) { System.out.print("B "); value1 = 10; } if (value2 < 10) { System.out.print("C "); if(value1 < 9) { System.out.print("D "); } else { value2++; } } System.out.println(value1 + " " + value2); A C D 8 6 (2 marks) d) What is the output produced by 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 / 20

2012SSTestAnswers - CompSci 101 CONTINUED 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