{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 2012SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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

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)

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) + 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)

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 (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? String diceValues = "23456234"; int position = diceValues.indexOf("1"); if (position > -1) { System.out.println("Stop " + position); } else { System.out.println("Go " + position); } Go -1 (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: ........................................................... 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); WT (2 marks) f) What is the output produced by the following code?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern