2008S2TestAnswers

2008S2TestAnswers - 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
CompSci 101 THE UNIVERSITY OF AUCKLAND CONTINUED SECOND SEMESTER, 2008 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:
Background image of page 1

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 S2 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED CompSci 101 Test Results Question Marks Out of Question 1 20 Question 2 10 Question 3 15 Question 4 20 Question 5 20 Question 6 15 TOTAL 100
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 S2 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (20 marks) What is displayed by each of the following pieces of Java program? a) System.out.println("\\/\\/"); \/\/ (2 marks) b) System.out.println(3 + Integer.parseInt("2") * 3); 9 (2 marks) c) int value = 500; // no calculator needed for this! System.out.println( (value / 456)*456 + (value % 456) ); 500 (2 marks) d) int i = 2; int[] numbers = {4, 2, -7, 5, 1, 6, 3}; System.out.println (numbers[i+1]); 5 (2 marks) e) String name = "bmi"; System.out.println(name.toUpperCase()); BMI (2 marks) f) String name = "plectrum"; System.out.println(name.substring(0, 2)+ name.substring(6)); plum (2 marks) g) String word = "supercalifragilisticexpialidotious"; String remark = "amusing"; if (word.length()>20) { remark = "sesquipedalian"; } System.out.println ("word is " + remark); word is sesquipedalian (2 marks)
Background image of page 3

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

View Full Document Right Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 S2 C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED h) int x = 5; double y = 4.0; System.out.println(Math.max(x, y)); // be careful! 5.0 (2 marks) i) int[] numbers = {2,3,4,5,6,7,8}; System.out.println(numbers[4]/numbers[1]); 2 (2 marks) j) String[] strings = {"panther","jaguar","ocelot","ounce"}; System.out.println(strings[3].length()); 5 (2 marks) Question 2 (10 marks) Add the return type to the following Java methods: a) private int calculateMinutes(double hours ) { return (int)(hours * 60); } (2 marks) b) private boolean isRepeated(String s) { String firstPart = s.substring(0,s.length()/2); return s.equals(firstPart+firstPart); }
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.

{[ snackBarMessage ]}

Page1 / 13

2008S2TestAnswers - 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