2011SSTestAnswers

2011SSTestAnswers - THE UNIVERSITY OF AUCKLAND SUMMER...

Info iconThis preview shows pages 1–6. 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: THE UNIVERSITY OF AUCKLAND SUMMER SEMESTER, 2011 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time Allowed: 75 minutes) NOTE: You must answer all questions in this test. No calculators are permitted Answer in the space provided in this booklet. There is space at the back for answers that overflow the allotted space. Surname Forenames Student ID Login (UPI) Lab Time Q1 (/12) Q4 (/10) Q7 (/7) Q10 (/8) Q2 (/9) Q5 (/6) Q8 (/10) Q11 (/8) Q3 (/12) Q6 (/8) Q9 (/10) Total /100 Question/Answer Sheet - Page 2 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... Question 1 (12 marks) a) What is the output produced by the following code? int a = 4; int b = 6; double c = b % a; System.out.println(a + a + ", " + b * c + 1); 8, 12.01 (2 marks) b) What is the output produced by the following code? int a = 1; double b = a + 0.1; System.out.println("" + a + b + (int) b); 11.11 (2 marks) Question/Answer Sheet - Page 3 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... c) What is the output produced by the following code? double factor = 0.99; int max = 10; int result = (int) factor * max + 2; System.out.println(result); 2 (2 marks) d) What is the output produced by the following code? String letters = "ABCDEFGH"; int n1 = letters.indexOf('B'); int n2 = letters.indexOf('E'); int n3 = letters.length(); System.out.println(n1 + n2 + letters.substring(0, n2) + n3); 5ABCD8 (2 marks) Question/Answer Sheet - Page 4 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... e) What is the output produced by the following code? String a = new String("abcd"); String b = new String("aBcD"); String c = new String("ABCD"); String d = b.toLowerCase(); if ( a == d ) { System.out.println("1"); } if ( a.substring(0,2).equals( d.substring(0,2) ) ) { System.out.println("2"); } if ( b.substring(1,2).equals( c.substring(1,2) ) ) { System.out.println("3"); } 2 3 (2 marks) f) What is the output produced by the following code? int a = 1; int b = 2; String s = a + "(" + (a == b) + ")" + b; System.out.println(s.length()); 9 (2 marks) Question/Answer Sheet - Page 5 - CompSci 101 SURNAME: ...................................................... FORENAMES: ........................................................... Question 2 (9 marks) a) Complete the header for the process() method. private String process ( int a, boolean b) { int c; if (b) { c = a / 2; } else { c = a * 2; } return c + "-" + b; } (3 marks) b) Complete the header for the process() method....
View Full 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

2011SSTestAnswers - THE UNIVERSITY OF AUCKLAND SUMMER...

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