2003SCTestAnswers

2003SCTestAnswers - COMPSCI 101 S2 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 S2 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2003 COMPUTER SCIENCE Principles of Programming TEST (Time allowed: 75 MINUTES) Surname: Forenames: Student ID number: Login name (UPI): Lab Group (e.g. Mon 1-3): INSTRUCTIONS: Attempt ALL questions - write your answers in the box provided Calculators are NOT permitted Question Mark Question Mark 1 (/15) 6 (/5) 2 (/10) 7 (/10) 3 (/5) 8 (/10) 4 (/15) 9 (/15) 5 (/15) 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 S2 SURNAME: . ..................................................... FORENAMES: . .......................................................... Question 1 (15 marks) (a) Write a statement which declares a variable called x as a boolean variable. boolean x; (1 mark) (b) Write an assignment statement which stores the value 34.0 in a variable called d. d = 34.0; (1 mark) (c) What is the output produced by the following code: System.out.println( Math.round( 4.7 ) ); 5 (1 mark) (d) What is the output produced by the following code: System.out.println( 3/4.0 + "5" ); 0.755 (1 mark) (e) What is the output produced by the following code: System.out.println( "5" + 3/4 ); 50 (1 mark) (f) What is the output produced by the following code: System.out.println( 5.0 + 4 + "3" + 2.0 + 1 ); 9.032.01 (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - COMPSCI 101 S2 SURNAME: . ..................................................... FORENAMES: . .......................................................... (g) What is the output produced by the following code: int n = 12; int m = 15; n = m; m = n; System.out.println(n + "^" + m); 15^15 (2 marks) (h) List all the identifiers which appear in the following code fragment. public static int getRandomNumber(int a, int b){ int number = (int)(Math.random()*(b-a+1))+a; return number; } getRandomNumber a b number Math random (2 marks) (i) What is the output produced by the following code: System.out.println( 11%5 + "^" + 5%11 ); 1^5 (2 marks) (j) What is the output produced by the following code: System.out.println( "+\"+\"+" ); +"+"+ (2 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 S2 SURNAME: . ..................................................... FORENAMES: . .......................................................... Question 2 (10 marks) The following code is supposed to read a number from the user and print out if the number is a prime number or not. However, the program contains a number of errors (both syntactical and logical), and will not compile nor would it produce the correct result if it did compile. Identify each of the errors by circling the relevant place in the code, and rewrite the line which contains the error in the space provided. One of the errors is corrected for you as an indication of what we expect. There are 10 errors remaining in the code. Note: You can assume that the readInput() method is included and that it contains no errors. import Java.io.*;
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.

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 / 15

2003SCTestAnswers - COMPSCI 101 S2 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