2005S2ExamQuestions

2005S2ExamQuestions - VERSION 1 COMPSCI 101 THE UNIVERSITY...

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

View Full Document Right Arrow Icon
VERSION 1 COMPSCI 101 THE UNIVERSITY OF AUCKLAND CONTINUED SECOND SEMESTER, 2005 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: Attempt ALL questions. Write all answers in the attached answer booklet. Answer the multiple choice questions in section A by circling the correct answer on the attached answer booklet. Write the answers to the questions in section B in the space provided on the attached answer booklet. Calculators are NOT permitted. SECTION A: MULTIPLE CHOICE QUESTIONS Each question in this section is worth 2.5 marks. Circle the letter corresponding to your choice on the attached answer sheet. There is only one correct answer for each question. 1. What is the output of the following statement? System.out.println(1 + 2 + "3" + 4 + 5); (a) 12345 (b) 15 (c) 1239 (d) 339 (e) 3345
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
VERSION 1 - 2 - COMPSCI 101 Question Sheet CONTINUED 2. Consider the following class stored in a file called MyApplication.java : public class MyApplication { public static void main(String[] args) { MyProgram p = new MyProgram(); p.start(); } } Also consider the following class stored in a file called MyProgram.java : public class MyProgram { public void start() { System.out.println("Hello World"); } } If MyApplication.java and MyProgram.java are both stored in the directory c:\myDir , which of the following commands will correctly compile and execute this program to produce the output " Hello World "? (a) c:\myDir> javac *.java c:\myDir> java MyProgram.class (b) c:\myDir> javac MyProgram.java c:\myDir> javac MyApplication.java c:\myDir> java MyApplication (c) c:\myDir> javac MyProgram.java c:\myDir> java MyApplication (d) c:\myDir> javac MyProgram.java c:\myDir> javac MyApplication.java c:\myDir> java MyApplication.class (e) c:\myDir> javac MyProgram.java c:\myDir> java MyApplication.class
Background image of page 2
VERSION 1 - 3 - COMPSCI 101 Question Sheet CONTINUED 3. What is the output produced by the following code? int x = 100; int y = x; x = 10; System.out.print(y); String s = "10"; String t = s.substring(0,1); System.out.println(s + t); (a) 1001010 (b) 100101 (c) 10011 (d) 10101 (e) 1011 4. What is the output of the following statement? System.out.println((1 + 2 * 3) / 4 + 5); (a) 0 (b) 1 (c) 6 (d) 6.75 (e) 7
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
VERSION 1 - 4 - COMPSCI 101 Question Sheet CONTINUED 5. What is the output of the following code segment? int a = 1; int b = 2; int c = 3; int d = Math.max(Math.min(a, b), Math.min(b, c)); System.out.println(d); (a) 1 (b) 2 (c) 3 (d) 6 (e) none of the above 6. What are all of the possible numbers that can be generated by the following expression? (int)(Math.random()*6) + 4; (a) 0 (b) 4, 5, 6, 7, 8, 9 (c) 6, 7, 8, 9 (d) 4, 5, 6 (e) none of the above
Background image of page 4
VERSION 1 - 5 - COMPSCI 101 Question Sheet CONTINUED 7. What is the output produced by the following code? int[] nums = { 1, 2, 3, 4, 5 };
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 / 25

2005S2ExamQuestions - VERSION 1 COMPSCI 101 THE UNIVERSITY...

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