2011S1TestAnswers

2011S1TestAnswers - VERSION 00000003 COMPSCI 101 THE...

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

VERSION 00000003 COMPSCI 101 CONTINUED THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2011 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time Allowed: 75 minutes) Note: The use of calculators is NOT permitted. For Section A, use a dark pencil to mark your answers in the answer boxes on the Teleform sheet. There is one correct answer per question. Each question is worth 2 marks. For Section B, write your answers in the spaces provided in this booklet. Write as clearly as possible. The space provided will generally be sufficient but is not necessarily an indication of the expected length. Extra space is provided at the end of this exam book. Surname: First Name(s): Student ID: Login Name (UPI): LAB TIME: where your marked test will be returned Day of week Starting time of lab –– MARKERS ONLY –– Question Marks Out Of 1 - 20 40 21 23 22 22 23 15 Total 100

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

View Full Document
VERSION 00000003 - 2 - COMPSCI 101 CONTINUED 1) What is the output of the following code segment? int a = 10; int b = 20; int c; c = a; a = b; b = c; System.out.println(a); System.out.println(b); (a) 20 20 (b) 10 20 (c) 20 10 (d) 10 10 (e) This code will not compile because c is not initialized to a literal value. 2) What output is produced when the following code is executed? System.out.println(1 + 4 + 3 * 5 / 2 + " + " + 4 + 4); (a) 12 + 44 (b) 12.5 + 8 (c) 11 + 44 (d) 12.5 + 44 (e) 12 + 8
VERSION 00000003 - 3 - COMPSCI 101 CONTINUED 3) Consider the following set of conditional statements: if (x % 2 == 1) { if ((x / 2 < 15) && (x > 10)) { System.out.println("TRUE"); } } This segment of code will produce the output "TRUE" when x has what value? (a) 31 (b) 5 (c) 12 (d) 21 (e) There is no value for x that will cause "TRUE" to be printed 4) What output is produced when the following code is executed? int a = 16; int b = 7; int c = a % a; int d = b % (b + 1); int e = a % b; int sum = c + d + e; System.out.println("sum: " + sum); (a) sum: 19 (b) sum: 9 (c) sum: 2 (d) sum: 3 (e) None of the above

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

View Full Document
VERSION 00000003 - 4 - COMPSCI 101 CONTINUED 5) What output is produced by the following code? int x = 10; int y = 5; if (x < 10) { if (y != 5) { System.out.println("aaa"); } else { System.out.println("bbb"); } } else if (y < 10) { System.out.println("ccc"); } else { if (y != 15) { System.out.println("ddd"); } else { System.out.println("eee"); } } (a) bbb (b) ccc (c) eee (d) ddd (e) aaa
VERSION 00000003 - 5 - COMPSCI 101 CONTINUED 6) What is the output of the following code? String a, b, c; a = new String("cat"); b = a; a = new String("dog"); c = b; System.out.println(a); System.out.println(b); System.out.println(c); (a) dog dog dog (b) cat dog dog (c) dog cat cat (d) dog dog cat (e) cat cat cat

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

View Full Document
VERSION 00000003 - 6 - COMPSCI 101 CONTINUED 7) Consider the following code (notice that the values assigned to variables a and b have been replaced with ??? ): boolean a = ??? ; boolean b = ??? ; boolean result = (!a || b) || b; What values should be assigned to variables a and b such that the variable
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 24

2011S1TestAnswers - VERSION 00000003 COMPSCI 101 THE...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online