2002ACTestQuestions

2002ACTestQuestions - C ompSci 101 AC 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 AC THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SCHOOL, 2002 COMPUTER SCIENCE Principles of Programming TERMS TEST (Time allowed: 75 MINUTES) Surname: Forenames: Student ID number: Lab time: Circle ONE of the following: Thursday 11-1 Friday 11-1 Thursday 1-3 Friday 1-3 Thursday 3-5 Friday 3-5 INSTRUCTIONS: Attempt ALL questions - write your answers in the box provided Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 (/10) 6 (/6) 2 (/10) 7 (/6) 3 (/10) 8 (/6) 4 (/10) 9 (/10) 5 (/10) 10 (/7) 11 (/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 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) a) What would be printed out by the following code segment? String s1 = new String("character"); String s2 = s1.substring(4,5); int i = s1.indexOf(s2); System.out.println(i + s1.substring(6,9)); (1 mark) b) What is printed by the following? System.out.println(1 + 2 + "." + 3 + 4); (1 mark) c) Would the following code compile, or is there a syntax error (circle the correct answer)? int i = Integer.parseInt(String.valueOf(8)); THE CODE WILL COMPILE / SYNTAX ERROR (1 mark) d) What is the output of the following code segment? System.out.print(1); System.out.println(2); System.out.print(3 + "\n"); System.out.println(4); System.out.print(5); System.out.println(6); (2 marks)
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED e) Write a single System.out.println() statement that produces the two lines of output exactly as shown below: \n\ \\n System.out.println( ); (1 mark) f) What is the output of the following code segment? int i = 8%17; i = i * 10; System.out.println("i is: " + i); (1 mark) g) What is the output of the following code segment? double d = 25/10; d = d + 2.5; System.out.println("d is: " + d); (1 mark) h) What is the output of the following code segment: int i = 1 / 2 + 3 / 4 - 5 * 6 - (7 + 8) * 9; System.out.println(i); (1 mark) i) What is the output of the following code segment: String s1 = "Hello"; String s2 = s1; s1 = s2.substring(0,1); System.out.println(s2.length()); (1 mark)
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 AC SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (10 marks) You need to locate and correct the errors in the application Q2 . What the application is supposed to do is prompt the user to enter their name and a number. You can assume that the number the user enters is an integer between 1 and 15.
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 / 18

2002ACTestQuestions - C ompSci 101 AC 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