2010SSTestAnswers

2010SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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

View Full Document Right Arrow Icon
CompSci 101 CONTINUED THE UNIVERSITY OF AUCKLAND SUMMER SEMESTER, 2010 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 Time Q1 (/10) Q4 (/10) Q7 (/18) Q2 (/10) Q5 (/12) Q8 (/15) Q3 (/15) Q6 (/10) Total /100
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)); 8 + 2 * 83 (2 marks) b) What is the output produced by the following code? System.out.println("A\"nB\n\\nZ"); A"nB \nZ (2 marks) c) Complete the output produced by the following code. int num = Math.min(Math.max(Math.min(3, 6), 5), 4); System.out.println("num: " + num); num: 4 (2 marks)
Background image of page 2
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 + a; System.out.println("a: " + a + " b: " + b + " c: " + c); a: 6 b: 3 c: 7 (2 marks) e) Complete the output produced by the following code: int a = 8 / 3; int b = 8 % 3; double c = 8 / 3; System.out.println("a: " + a + " b: " + b + " c: " + c); a: 2 b: 2 c: 2.0 (2 marks)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 ID: . .......................................................... CONTINUED Question 2 (10 marks) a) The int variable, number , has the value 9. Complete the output produced by the following code: boolean result; result = (number == 3 || number <= 0) && number!= 4; System.out.println("result: " + result); result: false (2 marks) b) The int variable, number , has the value 9. Complete the output produced by the following code: boolean result = !(number < 0) && number >= 3; System.out.println("result: " + result); result: true (2 marks) c) Write a boolean expression which tests whether the int variable, number , contains a value between 5 and 10 (inclusive). number >= 5 && number <=10 (2 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 ID: . .......................................................... CONTINUED d) 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; } else if (value2 < 10) { System.out.print("C "); if(value1 < 20) { System.out.print("D "); } value2 = value2 / 2; } System.out.println(value1 + " " + value2); A C D 8 3 (2 marks) e) What is the output produced by the following code? int value1 = 5; 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 < 20) { System.out.print("D "); } value2 = value2 / 2; } System.out.println(value1 + " " + value2); A B C D 10 3 (2 marks)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 6 - CompSci 101 ID: . ..........................................................
Background image of page 6
Image of page 7
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 / 21

2010SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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