2007SSExamQuestions

2007SSExamQuestions - COMPSCI 101 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 THE UNIVERSITY OF AUCKLAND CONTINUED SUMMER SEMESTER, 2007 Campus: City 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: Forenames: Student ID number: Login name: Q1 (/20) Q4 (/6) Q7 (/13) Q10 (/6) Q2 (/8) Q5 (/8) Q8 (/10) Q3 (/5) Q6 (/11) Q9 (/13) 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
- 2 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED Question 1 (20 marks) a) Assume that the current directory contains a Java source file named MyProgram.java . The following DOS command is used to compile the source file: javac MyProgram.java If the file compiles successfully, what is the name of the new file that will be created? (2 marks) b) One of the lines of code in the following program is surrounded by a comment. What is the output of the program? public class MyProgram{ public void start(){ int x = 100; if (x > 50) { System.out.println("A"); /* } else { */ System.out.println("B"); } } } (2 marks)
Background image of page 2
- 3 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED c) The positive() method is called in the following way: int[] x = {1,2,3,4,5}; int[] nums = positive(x, true); Complete the method header for the positive() method (i.e. complete the first line of the method definition). private { for (int i = 0; i < nums.length; i++) { if ((nums[i] < 0) && (b)) { nums[i] = -nums[i]; } } return nums; } (2 marks) d) What is the output of the following code? String a = new String("hello"); String b = new String("hello"); String c; c = a; System.out.println(a.equals(b)); System.out.println(a == b); System.out.println(a.equals(c)); System.out.println(a == c); System.out.println(b.equals(c)); System.out.println(b == c); (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
- 4 - COMPSCI 101 Question/Answer Sheet ID: . .................................................................... CONTINUED e) What is the output of the following code? int[] nums = {1, -2, 3, -4, 5}; for (int i = 0; i < nums.length; i++) { if (nums[i] < 0) { nums[i] = -1 * nums[i]; } } for (int i = 0; i < nums.length; i++) { System.out.print(nums[i] + " "); } (2 marks) f) What is the output of the following code? String a = "123"; System.out.println(a + 1); System.out.println(Integer.parseInt(a) + 1); (2 marks) g) What is the output produced by the following code? int a = 1 + 2 * 3 - 4 * 5 / 6 + 7 % 8 + 9; System.out.println(a); (2 marks)
Background image of page 4
- 5 - COMPSCI 101 Question/Answer Sheet ID: . ....................................................................
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.

Page1 / 23

2007SSExamQuestions - COMPSCI 101 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