2003ACExamQuestions

2003ACExamQuestions - CompSci 101 SS C THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
CompSci 101 SS C THE UNIVERSITY OF AUCKLAND CONTINUED Summer School, 2003 City Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO HOURS) Surname: Forenames: Student ID number: Login name (UPI): INSTRUCTIONS: Attempt ALL questions - write your answers in the box provided Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 (/5) 6 (/10) 2 (/5) 7 (/10) 3 (/10) 8 (/15) 4 (/15) 9 (/10) 5 (/15) 10 (/5) TOTAL: (/100)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 2 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (5 marks) a) What is printed by the following? int a = 10; System.out.println( a / (double)4 ); (1 mark) b) What is printed by the following? double b = (int)1.5; System.out.println(b); (1 mark) c) What is printed by the following? int c = (1 + 2 * 3) / 4 - 5 + 6 * 7 / 8 - 9; System.out.println(c); (1 mark) d) What is printed by the following? String d = "hello"; System.out.println(d.length() + 5); (1 mark) e) What is printed by the following? int e = Integer.parseInt("" + 5 + 3); System.out.println(e - 3.5); (1 mark)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (5 marks) You need to locate and correct the errors in the application Q2 . What the application is supposed to do is add together two integers and print the result to the screen. For example, when the correct application is run the output should be as shown below: C:/> java Q2 The sum is: 68 The source code for the application Q2 is given below, however it is not correct - it contains five syntax errors. You need to locate the syntax errors in the source code below. For each error you must clearly circle the error and also provide a correction . You do not need to write out the whole line of source code again, as long as you indicate your correction clearly. public class Q2 /* A program to add two numbers together /* public static void pain(String[] args) { int a = 23; int b = 45; int c == sum(a, b); System.out.println("The sum is: " + c); } public int sum(int a, int b) { return a + b; } } (5 marks)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Question/Answer Sheet - Page 4 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 3 (10 marks) Write the method removeRandomChars() which accepts two parameters, a String and an int ; the second parameter dictates how many characters are to be removed from the String .
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.

Page1 / 24

2003ACExamQuestions - CompSci 101 SS C THE UNIVERSITY OF...

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