2008S1TestAnswers

2008S1TestAnswers - 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
CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED FIRST 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:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 S1 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 40 Question 2 9 Question 3 8 Question 4 8 Question 5 8 Question 6 10 Question 7 7 Question 8 10 TOTAL 100
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 S1 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (40 marks) a) What is the output produced by the following code? int a = 6 + 1 * 7 - 4 * 5 / 8 + 7 % 3 - 2; System.out.println(a); 10 (2 marks) b) What is the output produced by the following code? String a = 6 + 1 + "OVER" + 1 + 1; System.out.println(a); 7OVER11 (2 marks) c) What is the output produced by the following code? System.out.println("A\nB\\n\"n"); A B\n”n (2 marks)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 S1 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED d) Complete the following code so that the output when the code is executed is: SAME String a = new String("hello"); String b = a; if (a == b) { System.out.println("SAME"); } (2 marks) e) Complete the following code so that the output when the code is executed is: PER String a = new String("SUPERMAN"); String b = a.substring( 2, 5 ); System.out.println(b); (2 marks) f) Write a Java statement which defines an int constant, SURCHARGE , which holds the value 10. final int SURCHARGE = 10; (2 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 S1 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED g) The following statement assigns a random number to the variable, a . What are ALL the possible values which can be assigned to the variable, a ? int a = (int) (Math.random() * 2) + 3; 3, 4 (2 marks) h) What is the output produced by the following code? int a = Math.min(Math.min(4, 5), Math.max(8, 12)); System.out.println(a); 4 (2 marks) i) Complete the following code so that the output when the code is executed is: UP String a = new String("SUPERWOMAN"); char c1 = a.charAt( 1 ); char c2 = a.charAt( 2 ); String s = "" + c1 + c2; System.out.println(s); (2 marks)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 6 - CompSci 101 S1 C SURNAME: . ..................................................... FORENAMES: . ..........................................................
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

2008S1TestAnswers - 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