{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2002FCTestQuestions - C OMPSCI 101FC Principles of P...

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

View Full Document Right Arrow Icon
Family name or surname Given names Lab Day and Time (e.g. Monday 9) Instructions This test constitutes 15% of your final grade for the course. No one is to leave in the last 10 minutes. The test is closed book. No calculators are allowed. There are 100 marks in this test. The marks for each question are shown. Answer all questions in this booklet. Write your UPI on every page. You do NOT have to include JavaDoc comments unless the question asks for them. Use good indenting and naming styles. See page 15 for a list of methods you may find useful in your answers. You may use pages 15 and 16 as extra space. COMPSCI 101FC Principles of Programming Test and Answer Book Test - Thursday 18th April 6:30pm-8:00pm
Image of page 1

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

View Full Document Right Arrow Icon
COMPSCI 101FC 2002 T EST A ND A NSWER B OOK PAGE 2 S TUDENT UPI: Student ID number Student UPI (Login name) Signature Marks: (for markers use only) Question Mark Question Mark 1 9 2 10 3 11 4 12 5 13 6 14 7 8 Total
Image of page 2
COMPSCI 101FC 2002 T EST A ND A NSWER B OOK PAGE 3 S TUDENT UPI: Question 1 (11 marks) a) What would be printed out by the following code segment? int i = 10; double d = i / 3; System.out.println(d); (1 mark) b) What is printed by the following? System.out.println(7 + 7 + 7 + "7" + (7 + 7) + 7); (1 mark) c) Write an expression to generate a random integer between 8 and 13 (including 8 and 13) and assign it to the variable i . int i = (1 mark) d) What is the output of the following code segment? System.out.println("a"); System.out.print("a"); System.out.println("a"); System.out.print("a"); System.out.println("a" + "b"); System.out.println("a"); (2 marks)
Image of page 3

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

View Full Document Right Arrow Icon
COMPSCI 101FC 2002 T EST A ND A NSWER B OOK PAGE 4 S TUDENT UPI: e) What is the output of the following code segment? double d = (int)(5.3 + 2.8); System.out.println(d); (1 mark) f) What is the output of the following code segment? System.out.println("\\n\""); (1 mark) g) What is the output of the following code segment? int i1 = 2 + 2 - 2 * 2 / 2; int i2 = 2 * 2 / 2 - 2 + 2; System.out.println(i1 + "." + i2); (1 mark) h) What is the output of the following code segment: int i = 9 - 8 - (7 * 6) / 5 + 4 - (3 + 2) * 2; System.out.println(i); (1 mark) i) What is the output of the following code segment: String s = "computer science"; String t = s.substring(3, 6); System.out.println(s.length() - t.length() + t); (2 marks)
Image of page 4
COMPSCI 101FC 2002 T EST A ND A NSWER B OOK PAGE 5 S TUDENT UPI: Question 2 (8 marks) Complete the following method which displays the question passed as a parameter and waits for the user to type a response. If the first character of the response is a “y”
Image of page 5

Info icon This 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 ]}