2007S2TestAnswers

2007S2TestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

Info iconThis preview shows pages 1–5. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED SECOND SEMESTER, 2007 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: Question/Answer Sheet - Page 2 - CompSci 101 S2 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 10 Question 2 5 Question 3 5 Question 4 10 Question 5 20 Question 6 10 TOTAL 60 Question/Answer Sheet - Page 2 - CompSci 101 S2 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 10 Question 2 5 Question 3 5 Question 4 10 Question 5 20 Question 6 10 TOTAL 60 Question/Answer Sheet - Page 3 - CompSci 101 S2 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 1 (10 marks) What is displayed by each of the following pieces of Java program? a) System.out.println("\"quote"); "quote (1 mark) b) System.out.println("X" + (2 + 3)); X5 (1 mark) c) int value = 13; System.out.println(value < 6); false (1 mark) d) int i = 5; int numbers = {4, 2, -7, 5, 1, 6, 3}; System.out.println (numbers[i]); 6 (1 mark) e) String name = "banana split"; System.out.println(name.indexOf('n')); 2 (1 mark) f) String name = "facile"; System.out.println(name.substring(1, 3)); ac (1 mark) g) String name = "peasy"; System.out.println(name.substring(1)); easy (1 mark) h) int x = 5, y = 4; System.out.println(Math.max(x, y)); 5 (1 mark) Question/Answer Sheet - Page 4 - CompSci 101 S2 C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED i) int numbers = {2,3,4,5,6,7,8}; System.out.println(numbers[0]*numbers[3]); 10 (1 mark) j) String strings = {"cat","dog","snake","ocelot"}; System.out.println(strings[2].length()); 5 (1 mark) Question 2 (5 marks) Add the return type to the following Java methods: a) private int addNums(int num1, int num2) { return num1 + num2; } (1 mark) b) private void printNumber(int num) { System.out.println(num); System....
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 / 13

2007S2TestAnswers - CompSci 101 THE UNIVERSITY OF AUCKLAND...

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