{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2003SCTestQuestions

2003SCTestQuestions - COMPSCI 101 S2 THE UNIVERSITY OF...

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

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)

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

View Full Document
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. (1 mark) (b) Write an assignment statement which stores the value 34.0 in a variable called d. (1 mark) (c) What is the output produced by the following code: System.out.println( Math.round( 4.7 ) ); (1 mark) (d) What is the output produced by the following code: System.out.println( 3/4.0 + "5" ); (1 mark) (e) What is the output produced by the following code: System.out.println( "5" + 3/4 ); (1 mark) (f) What is the output produced by the following code: System.out.println( 5.0 + 4 + "3" + 2.0 + 1 ); (2 marks)
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); (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; } (2 marks) (i) What is the output produced by the following code: System.out.println( 11%5 + "^" + 5%11 ); (2 marks) (j) What is the output produced by the following code: System.out.println( "+\"+\"+" ); (2 marks)

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 16

2003SCTestQuestions - COMPSCI 101 S2 THE UNIVERSITY OF...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online