{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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:

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

View Full Document
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
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)

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

View Full Document
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)));
Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Show the output here: 1. ADA 2. 2 3. -1 4. A 5. not == 6. equal 7. true 8. true 9. true 10. false (10 marks)

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

View Full Document
Question/Answer Sheet - Page 6 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ...........................................................
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}