{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2012SSTestQuestions - 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
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 (/10) Q4 (/16) Q7 (/10) Q2 (/12) Q5 (/20) Total /100 Q3 (/12) Q6 (/20)
Background image of page 1

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

View Full Document Right 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) + 3); (2 marks) b) What is the output produced by the following code? System.out.println("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: (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 + c; c = c + 2; 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 = 2 + 7 % 3; int b = 8 % 11; double c = 15 / 4; System.out.println("a: " + a + " b: " + b + " c: " + c); a: b: c: (2 marks)
Background image of page 3

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

View Full Document Right Arrow Icon
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: (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); (2 marks)
Background image of page 4
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); (2 marks) d) What is the output produced by the following code? String diceValues = "23456234"; int position = diceValues.indexOf("1"); if (position > -1) { System.out.println("Stop " + position); } else { System.out.println("Go " + position); } (2 marks)
Background image of page 5

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 6 - CompSci 101 ID: ........................................................... CONTINUED e) What is the output produced by the following code? String word = "WHAT HAPPENS IF YOU GET SCARED HALF TO DEATH TWICE?"; String result = "" + word.charAt(0) + word.charAt(word.length() - 6); System.out.println(result); (2 marks) f) What is the output produced by the following code?
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.

{[ snackBarMessage ]}