2007S2ExamAnswers

2007S2ExamAnswers - COMPSCI 101 THE UNIVERSITY OF AUCKLAND...

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: COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED SECOND SEMESTER, 2007 Campus: City COMPUTER SCIENCE Principles of Programming (Time allowed: TWO hours) 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: Q1 (/20) Q4 (/13) Q7 (/8) Q2 (/9) Q5 (/17) Q8 (/10) Q3 (/8) Q6 (/5) Q9 (/10) TOTAL (/100)- 2 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED Question 1 (20 marks) What is displayed by each of the following pieces of Java program? a) System.out.println("\"x\""); "x" (2 marks) b) int value = Math.max(1, Math.max(2, 3)); System.out.println("Max is: " + value); Max is: 3 (2 marks) c) int value = 13; System.out.println(6 < value && value < 20); true (2 marks) d) String name = "frantic"; int number = name.indexOf('i'); System.out.println(name.substring(2, number)); ant- 2 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED Question 1 (20 marks) What is displayed by each of the following pieces of Java program? a) System.out.println("\"x\""); "x" (2 marks) b) int value = Math.max(1, Math.max(2, 3)); System.out.println("Max is: " + value); Max is: 3 (2 marks) c) int value = 13; System.out.println(6 < value && value < 20); true (2 marks) d) String name = "frantic"; int number = name.indexOf('i'); System.out.println(name.substring(2, number)); ant- 3 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED (2 marks) e) double d = 23.7; double e = 5.2; System.out.println((int)(Math.round(d + e))); 29 (2 marks) f) int i = 5; int numbers = { 4, 2, -7, 5, 1, 6, 3 }; System.out.println(numbers[i] + numbers[i+1]); 9 (2 marks) g) String name = "facile"; System.out.println(name.substring(1, 3) + name.charAt(5)); ace (2 marks)- 4 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED h) int x = 8; int y = 3; System.out.println(x/y + " * " + y + " + " + x%y + " == " + x); 2 * 3 + 2 == 8 (2 marks) i) int numbers = { 2, 3, 4, 5, 6, 7, 8 }; int value, i; i = 3; value = Math.max(numbers[i], numbers[i-1]); System.out.println(value); 5 (2 marks) j) String word; String s = {"cat", "dog", "snake", "ocelot", "rabbit" }; word = s[4].charAt(0) + s[0].substring(1); System.out.println(word); rat (2 marks) - 5 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED Question 2 (9 marks) Complete each of the methods below as specified in the comment preceding each 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 / 24

2007S2ExamAnswers - COMPSCI 101 THE UNIVERSITY OF AUCKLAND...

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