2011SSExamQuestions

2011SSExamQuestions - CompSci 101 CONTINUED THE UNIVERSITY...

Info iconThis preview shows pages 1–7. 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, 2011 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this exam. 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) Q1 (/8) Q4 (/8) Q7 (/13) Q10 (/7) Q2 (/9) Q5 (/6) Q8 (/9) Q11 (/7) Q3 (/8) Q6 (/5) Q9 (/10) Q12 (/10) Total (/100) Question/Answer Sheet - Page 2 - CompSci 101 ID: ........................................................... CONTINUED Question 1 (8 marks) a) What output is produced by the following code? int a = 4; int b = 6; double c = b % a; System.out.println(a + a + ", " + b * c + 1); (2 marks) b) Complete the output of the following code. int a = 4; int b = a + 6; double c = 1.0 * b / a; a = a + (int) (a * c) + 1; b++; System.out.println("a: " + a + " b: " + b + " c: " + c); a: b: c: (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 ID: ........................................................... CONTINUED c) What output is produced by the following code? int x = 13; int y = 5; if (x < 10) { if (y != 5) { System.out.println("A"); } else { System.out.println("B"); } } else if (y > 10) { System.out.println("C"); } else { if (y != 5) { System.out.println("D"); } else { System.out.println("E"); } } (2 marks) d) In the space provided below, assign a value for the variable, y , so that the output of the section of code is: int x = 8; int y = if (x < 10 && !(y > 7 || y == x)) { if (y % 2 == 0) { System.out.println("AA"); } else { System.out.println("BB"); } } else if (y > 2) { System.out.println("CC"); } (2 marks) ; AA Question/Answer Sheet - Page 4 - CompSci 101 ID: ........................................................... CONTINUED Question 2 (9 marks) a) What output is produced by the following code? boolean a1 = { true, false, false, true }; boolean a2 = { false, false, true, true }; for (int i = 0; i < a1.length; i++) { System.out.print((a1[i] || !a2[i]) + " "); } (3 marks) b) Complete the output when the following code is executed. String s = new String[4]; s[0] = "0"; for (int i = 1; i < s.length; i++) { s[i] = s[i-1] + s[i-1].length(); } System.out.print("s: "); for (int i = 1; i < s.length; i++) { System.out.print(s[i] + " "); } s: (3 marks) Question/Answer Sheet - Page 5 - CompSci 101 ID: ........................................................... CONTINUED c) What output is produced by the following code? String array = { "3", "to", "One" }; for (int i = 0; i < array.length; i++) { array[i] = "-" + array[i].length(); } for (int i = 0; i < array.length; i++) { System.out.print(i + array[i] + ","); } (3 marks) Question/Answer Sheet - Page 6 - CompSci 101 ID: ..............................................................
View Full Document

Page1 / 34

2011SSExamQuestions - CompSci 101 CONTINUED THE UNIVERSITY...

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