2005SSTestAnswers

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

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

View Full Document Right Arrow Icon
CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2005 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 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 (output) 10 Question 2 (output) 10 Question 3 (keyboard input) 10 Question 4 (conditionals) 10 Question 5 (loops) 10 Question 6 (loops) 10 Question 7 (methods) 10 Question 8 (methods) 10 Question 9 (arrays) 10 Question 10 (desk-checking) 10 TOTAL 100
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) a) What is printed by the following? double a; a = 1 / 2; System.out.println( a ); 0.0 (2 marks) b) What is printed by the following? int x = 9 - 8 + 7 / 6 - 5 % (4 + 3) * 2 - 1; System.out.println( x ); -9 (2 marks) c) What is printed by the following? System.out.println( "\" + \"\"" ); " + "" (2 marks) d) What is printed by the following? double rand = 0.6; System.out.println( (int)rand * 100 + 1 ); 1 (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 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED e) What is printed by the following? int b = (int)(2.5 * 2.0) - (int)3.99; System.out.println( b ); 2 (2 marks) Question 2 (10 marks) What is the output when the following code is executed? int num1 = 4; int num2 = 7; String word1 = new String( "ABRACADABRA" ); String word2 = new String( word1.toUpperCase() ); String word3 = new String( " TO SING " ); System.out.println("1. " + word1.substring(5, 8)); System.out.println("2. " + word1.indexOf("RA")); System.out.println("3. " + word1.indexOf('P')); System.out.println("4. " + word1.charAt(3)); if (word2 == word1) System.out.println("5. =="); else System.out.println("5. not =="); if (word2.equals(word1)) System.out.println("6. equal"); else System.out.println("6. not equal"); System.out.println("7. " + (word1 == word1)); System.out.println("8. " + (num2/num1>=1 || (num2/3.0>2))); System.out.println("9. " + ( !(num2 != 7))); System.out.println("10. " + (num2%2==1 && !(num1>3)));
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . ..........................................................
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 20

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online