2008SSTestAnswers

2008SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2008 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time allowed: 75 MINUTES) NOTE: Attempt ALL questions Write your answers in the space provided There is space at the back for answers that overflow the allotted space No calculators are permitted Surname: Forenames: Student ID number: Login name: Question/Answer Sheet - Page 2 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 26 Question 2 10 Question 3 10 Question 4 10 Question 5 6 Question 6 7 Question 7 7 Question 8 24 TOTAL 100 Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 1 (26 marks) a) What output is produced by the following code? System.out.println("nn\nn\nn"); nn n n (2 marks) b) The following expression will evaluate to one of THREE different values. What are these THREE possible values? int value = (int)(Math.random()*3) * 3 + 2; 2, 5 and 8 (2 marks) c) What would be printed by the following? int x = Math.max(Math.max(4, 5), Math.min(6, 7)); System.out.println(x); 6 (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED d) What output is produced by the following code? String a, b; a = new String("cs101"); b = a; a = b.substring(1,3); System.out.println(a + b); s1cs101 (2 marks) e) What output is produced by the following code? int number = 100; while (number % 2 == 0) { number = number / 2; System.out.println(number); } 50 25 (2 marks) f) What would be printed by the following? String a = "4"; int x = Integer.parseInt(a); x = 10 + x; System.out.println(x); 14 (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED g) What output is produced by the following code? double x; x = 1 / 2; System.out.println(x); 0.0 (2 marks) h) What output is produced by the following code? int a = 1; int b = 2; int c = 3; a = c; c = b; b = a; System.out.println(a + " " + b + " " + c); 3 3 2 (2 marks) i) What would be printed by the following? System.out.println((1 + 2 * 3) / 6); 1 (2 marks) Question/Answer Sheet - Page 6 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ..............................................................
View Full Document

Page1 / 18

2008SSTestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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