2007S2ExamQuestions

2007S2ExamQuestions - COMPSCI 101 THE UNIVERSITY OF...

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\""); (2 marks) b) int value = Math.max(1, Math.max(2, 3)); System.out.println("Max is: " + value); (2 marks) c) int value = 13; System.out.println(6 < value && value < 20); (2 marks) d) String name = "frantic"; int number = name.indexOf('i'); System.out.println(name.substring(2, number)); (2 marks)- 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\""); (2 marks) b) int value = Math.max(1, Math.max(2, 3)); System.out.println("Max is: " + value); (2 marks) c) int value = 13; System.out.println(6 < value && value < 20); (2 marks) d) String name = "frantic"; int number = name.indexOf('i'); System.out.println(name.substring(2, number)); (2 marks)- 3 - COMPSCI 101 Question/Answer Sheet ID: ........................................................ CONTINUED e) double d = 23.7; double e = 5.2; System.out.println((int)(Math.round(d + e))); (2 marks) f) int i = 5; int numbers = { 4, 2, -7, 5, 1, 6, 3 }; System.out.println(numbers[i] + numbers[i+1]); (2 marks) g) String name = "facile"; System.out.println(name.substring(1, 3) + name.charAt(5)); (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 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); (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); (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. a) //method which returns the largest of three numbers private int largest(int x1, int x2, int x3) { } (3 marks) b) //method which returns a boolean indicating whether one //String starts with the same character as another String //You can assume that both s1 and s2 contain at //least one character private boolean sameFirstLetter(String s1, String s2) { } (3 marks)...
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

2007S2ExamQuestions - COMPSCI 101 THE UNIVERSITY OF...

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