2002ACExamQuestions

2002ACExamQuestions - C ompSci 101 AC THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 AC THE UNIVERSITY OF AUCKLAND CONTINUED Summer School, 2002 City Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) Surname: Forenames: Student ID number: INSTRUCTIONS: Attempt ALL questions - write your answers in the space provided Marks for each question are shown, and total 100. There is extra space on the last page of the booklet if you need it There is an appendix at the end of this booklet which lists some useful methods Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 (/10) 7 (/5) 2 (/5) 8 (/10) 3 (/10) 9 (/5) 4 (/15) 10 (/8) 5 (/15) 11 (/12) 6 (/5) TOTAL: (/100)
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 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) a) What is the output of the following? String s = "hello"; System.out.println(s.indexOf("A")); (2 marks) b) What is the output of the following? System.out.println(5 + 5 + 5 + "." + (5 + 5) + 5); (2 marks) c) What is the output of the following? double d = 10 + 25 / 10; System.out.println("d is: " + d); (2 marks) d) What is the output of the following? String s1 = "2"; String s2 = "3"; int i = 100 + Integer.parseInt(s1 + s2); System.out.println("i is : " + i); (2 marks) e) What is the output of the following? String s = "apple"; System.out.println(s.lastIndexOf('p')); (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (5 marks) Complete the randomString() method below, which is passed an array of String s as a parameter, and returns one of the String s from the array at random. Every String in the array should have the same probability of being returned. private static String randomString(String[] words) { } As an example, if the following main() method was executed: public static void main(String[] args) { String[] a = {"a", "b", "c", "d", "e"}; System.out.println(randomString(a)); System.out.println(randomString(a)); System.out.println(randomString(a)); } possible output might be: b a d
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 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 3 (10 marks) Write a method called flipHorizontal() which takes a 2-dimensional rectangular array of int s as a parameter and returns a new 2-dimensional rectangular array of int s. The returned array should consist of the same values as the original array except every row of values is flipped horizontally i.e.
Background image of page 4
Image of page 5
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 / 24

2002ACExamQuestions - C ompSci 101 AC THE UNIVERSITY OF...

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

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