2008S1ExamQuestionsV1

2008S1ExamQuestionsV1 - VERSION 18832768-1 COMPSCI 101 THE...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
VERSION 18832768 - 1 - COMPSCI 101 CONTINUED THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2008 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: Attempt ALL questions. Answer Section A (Multiple choice Questions) on the teleform answer sheet attached. Answer Section B in the spaces provided in this booklet. Calculators are NOT permitted. Surname: Forenames: Student ID number: Login name: Q1 – Q20 Multi-choice (/50) Q23 (/4) Q26 (/6) Q29 (/6) Q21 (/4) Q24 (/6) Q27 (/6) Q22 (/6) Q25 (/6) Q28 (/6) TOTAL (/100)
Image of page 1

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

View Full Document Right Arrow Icon
VERSION 18832768 - 2 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED SECTION A MULTIPLE CHOICE QUESTIONS Each question in this section is worth 2.5 marks. There is only one correct answer for each question. Select your preferred alternative on the teleform answer sheet provided . 1. What is the output produced by the following code? int a = 4; int b = a; int c = b; a = a + 1; b = b + 2; c = c + 3; b = a; a = b; System.out.println("a: " + a + " b: " + b + " c: " + c); (a) a: 5 b: 5 c: 7 (b) a: 5 b: 5 c: 5 (c) a: 7 b: 7 c: 7 (d) a: 6 b: 5 c: 7 (e) none of the above 2. Which one of the following expressions does NOT evaluate to 2?
Image of page 2
VERSION 18832768 - 3 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 3. What is the output of the following statement? int number = 100; while (number % 2 == 0) { System.out.print(number + " "); number = number / 2; } 4. What is the output of the following code? String[] s = new String[3]; s[0] = new String("zero"); s[1] = new String("one"); s[2] = new String("two"); s[1] = s[2]; s[0] = s[1]; s[2] = s[0]; for(int i = 0; i < s.length; i++) { System.out.print(s[i] + " "); }
Image of page 3

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

View Full Document Right Arrow Icon
VERSION 18832768 - 4 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 5. Which one of the five sections of code below does NOT produce the following output: output: AAAA (a) System.out.print("output: "); for (int i = 1; i < 5; i++) { System.out.print("A"); } (b) System.out.print("output: "); for (int i = 1; i < 5 && i != 0; i++) { System.out.print("A"); } (c) System.out.print("output: "); for (int i = 1; i < 5; ) { i = i + 1; System.out.print("A"); } (d) System.out.print("output: "); for (int i = 0; i < 7; i = i + 2) { System.out.print("A"); } (e) System.out.print("output: "); for (int i = 5; i > 0; i--) { System.out.print("A"); } 6. Consider the following boolean expression: (a && b) || (!a) What values would need to be stored in the boolean variables a and b so that this expression evaluates to false ?
Image of page 4
VERSION 18832768 - 5 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 7. Which one of the following method calls on the Graphics object would produce the outline of a square, which has a width and height of 50 pixels and which is centred at position (200, 200)? (a) g.drawRect(150, 150, 25, 25); (b) g.drawRect(150, 150, 50, 50); (c) g.drawRect(175, 175, 25, 25); (d) g.drawRect(175, 175, 50, 50); (e) g.drawRect(200, 200, 25, 25);
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern