2003ACTestQuestions

2003ACTestQuestions - C ompSci 1 01 S S C THE UNIVERSITY OF AUCKLAND SUMMER SCHOOL 2003 COMPUTER SCIENCE Principles of Programming TERMS TEST(Time

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

View Full Document Right Arrow Icon
CompSci 101 SS C THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SCHOOL, 2003 COMPUTER SCIENCE Principles of Programming TERMS TEST (Time allowed: 75 MINUTES) Surname: Forenames: Student ID number: Login name (UPI): INSTRUCTIONS: Attempt ALL questions - write your answers in the box provided Calculators are NOT permitted Examiner to complete: Question Mark Question Mark 1 (/15) 7 (/10) 2 (/10) 8 (/10) 3 (/3) 9 (/5) 4 (/6) 10 (/10) 5 (/6) 11 (/15) 6 (/10) 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 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (15 marks) a) What is printed by the following? System.out.println(5 / 2 * 2.5); (1 mark) b) What is printed by the following? System.out.println("Total = " + 5 + 1.5); (2 marks) c) What is printed by the following? System.out.println("Total = \" + 5 + 1.5"); (2 marks) d) What is printed by the following? System.out.println("n\\\n\\n"); (2 marks) e) What is printed by the following? System.out.println(9 * 8 + 7 / (6 - 5) * 4 + 3 / 2 - 1);
Background image of page 2
Question/Answer Sheet - Page 3 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED (2 marks) f) What is printed by the following? System.out.println(Math.max(Math.min(9,10), Math.max(-12,7))); (2 marks) g) What is printed by the following? String x = "Now"; String y = "Then"; System.out.println(x.length() + y.length()); (2 marks) h) Complete the program below so that it prints out a single random integer to the screen. The random integer must be an odd number between 1 and 99 (inclusive). In other words, the output of the program must be either 1, 3, 5, 7, 9, 11, . .., 97 or 99: public class OddInteger { public static void main(String[] args) { (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 SS C 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 generate three random numbers between 0 and 9, print them to the screen, and also calculate and print the average of the three numbers to the screen. For example, possible output when the correct application is run twice is given below: C:/> java Q2 The average of: 4, 2 and 8 is 4.6666666666666 C:/> java Q2 The average of: 3, 9 and 3 is 5.0 The source code for the application Q2 is given below, however it is not correct - it contains four syntax errors and one logic error. You need to locate the syntax errors and the logic error in the source code below. For each error you must clearly circle the error and also provide a correction . You do not need to write out the whole line of source code again, as long as you indicate your correction clearly. public Q2 { public static void main(String[] args) { int a; int b; it c; a = (int)(Math.random() * 10); b = (int)(Math.random() * 10); c = (int)(Math.random() * 10); double average = a + b + c / 3.0; System.out.print("The average of: "); System.out.print(a + ", " b + " and " + c); System.out.println(" is " + average) } } (10 marks)
Background image of page 4
Question/Answer Sheet - Page 5 - CompSci 101 SS C SURNAME: . ..................................................... FORENAMES: . ..........................................................
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 22

2003ACTestQuestions - C ompSci 1 01 S S C THE UNIVERSITY OF AUCKLAND SUMMER SCHOOL 2003 COMPUTER SCIENCE Principles of Programming TERMS TEST(Time

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