{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2002ACExamQuestions

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

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

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)

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

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

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

View Full Document
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. the last row becomes the first row, the second to last row becomes the second row and so on. For example, we can create the following rectangular array like this: int[][] a = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}, {16, 17, 18} }; We can visualize this array as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 If we call the method flipHorizontal() , and pass the above array as a parameter int[][] b = flipHorizontal(a); the returned array, b , can be visualized as below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 You can assume that the array passed in as a parameter to flipHorizontal() will always have at least two rows.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online