2001SCExamAnswers

2001SCExamAnswers - COMPSCI 101 SC/ST THE UNIVERSITY OF...

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

View Full Document Right Arrow Icon
COMPSCI 101 SC/ST THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2001 Campus: City/Tamaki 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 SOLUTIONS Forenames Student ID Login (UPI) Section Marks Out of SECTION A 25 SECTION B 25 SECTION C 25 SECTION D 25 Total 100
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
Candidate's Name:___________________ 2 COMPSCI 101 SC/ST SECTION A 1. Examine each of the following Java statements carefully. For each of the statements, tick the appropriate box to indicate either that the statement is correct, or if it contains any errors, then indicate the category of error (Syntax, Runtime or Logic). If the statement contains an error, then correct the error by writing a correct version of the statement below the original. (Note that there may be more than one way to correct an error - any sensible correction will be fine) (a) double d = "20.001"; Correct Syntax Error Runtime Error Logic Error double d = 20.001; (b) int i = new Integer(0); Correct Syntax Error Runtime Error Logic Error int i = 0; Integer i = new Integer(0); (c) String s = new String "0"; Correct Syntax Error Runtime Error Logic Error String s = new String("0"); (d) String t = 23 + " is the sum of 20 and 3"; Correct Syntax Error Runtime Error Logic Error (e) double g = 45.0/(2.0/3.0); Correct Syntax Error Runtime Error Logic Error (f) int j = 45/(2/3); Correct Syntax Error Runtime Error Logic Error
Background image of page 2
Candidate's Name:___________________ 3 COMPSCI 101 SC/ST int j = 45/(2.0/3.0); (g) String v = "The sum of 3 and 4 is" + 3 + 4; Correct Syntax Error Runtime Error Logic Error String v = "The sum of 3 and 4 is" + (3+4); (h) String w = "The product of 3 and 4 is" + 3 * 4; Correct Syntax Error Runtime Error Logic Error (i) int number34 = 34 Correct Syntax Error Runtime Error Logic Error int number34 = 34; (j) int k = Integer.parseInt("seven"); Correct Syntax Error Runtime Error Logic Error int k = Integer.parseInt("7"); (10 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
Candidate's Name:___________________ 4 COMPSCI 101 SC/ST 2. What is the output of each of the following fragments of code? (a) System.out.println( 2/10 * 10.0/2.0 ); 0 (b) System.out.println( 10.0/2.0 * 2/10 ); 1.0 (c) System.out.println( 20 + 5 + "0" + 2.5 + 5/10 ); 2502.50 (d) System.out.println( 3/2.0 + "^" + 3.0/2 ); 1.5^1.5 (e) System.out.println( 1.0 * (2+1)/(1+1) ); 1.5 (5 marks)
Background image of page 4
Candidate's Name:___________________ 5 COMPSCI 101 SC/ST 3. What is the output of the following application? public class Q3{ private static int small = -3; private static int big = 9; private static void a(int p, String display){ p = 0; display = display.toUpperCase(); System.out.print(p + display + "*"); } private static void b(int x, int y){ x = x + y; y = y + x; int small = x-y; big = x+y; System.out.print(small + "^" + big + "*"); } private static int b(int temp){ int b = temp + big; return b + b(); }
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 22

2001SCExamAnswers - COMPSCI 101 SC/ST 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