{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2010SSTestQuestions

# 2010SSTestQuestions - CompSci 101 THE UNIVERSITY OF...

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

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

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 is the output produced by the following code? System.out.println(3 + 5 + " + " + 2 + " * " + 8 + (2 + 1)); (2 marks) b) What is the output produced by the following code? System.out.println("A\"nB\n\\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: (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 + a; System.out.println("a: " + a + " b: " + b + " c: " + c); a: b: c: (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: b: c: (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 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: (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: (2 marks) c) Write a boolean expression which tests whether the int variable, number , contains a value between 5 and 10 (inclusive). (2 marks)
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); (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); (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.

{[ snackBarMessage ]}