2003SCExamQuestions

2003SCExamQuestions - COMPSCI 101 S2 C/T 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 S2 C/T THE UNIVERSITY OF AUCKLAND CONTINUED Second Semester, 2003 City/Tamaki Campus COMPUTER SCIENCE Principles of Programming (Time allowed: TWO HOURS) 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 (/10) 6 (/12) 2 (/20) 7 (/8) 3 (/4) 8 (/4) 4 (/10) 9 (/10) 5 (/12) 10 (/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 S2 C/T SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 1 (10 marks) (a) What is printed when the following statement is executed? System.out.println( 1 + 2.5 + "4" + 3/2.0 ); (1 mark) (b) What is printed when the following statement is executed? System.out.println( 103/10*10 ); (1 mark) (c) What is printed when the following statement is executed? System.out.println( 103%10 ); (1 mark) (d) What is printed when the following statement is executed? System.out.println( (true && false) || (true ^ true) ); (1 mark)
Background image of page 2
Question/Answer Sheet - Page 3 - COMPSCI 101 S2 C/T SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED (e) What is printed when the following statement is executed? System.out.println( (true || (true && false))|| false ); (1 mark) (f) What is printed when the following statement is executed? System.out.println( 2 > 3 && !(3 - 2 < 1 || 1 == 2) ); (1 mark) (g) Convert the following formula into a single Java statement. You may assume that the variables area and r have already been declared as doubles. area = 2 . 4 r π (2 marks) (h) Convert the following formula into a single Java statement. You may assume that the variables a, b and c have already been declared as doubles. c = 2 2 b a + (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 S2 C/T SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED Question 2 (20 marks) Read the following program and answer the questions below. Try to understand the purpose of the code. import java.io.*; public class Question02{ public static void main(String[] args){ System.out.print("Enter a number: "); int n = Integer.parseInt(readInput()); boolean result = check(n); System.out.println("Result: " + result); } private static boolean check(int n){ System.out.println("check: " + n); while(n!=0){ int om = getOM(n); int a = getMS(n, om); int b = getLS(n); n = (n%om)/10; if(a!=b) return false; } return true; } private static int getOM(int n){ int i=1; while(i<=n){ i=i*10; } i = i/10; System.out.println("getOM return: " + i); return i; } private static int getMS(int n, int om){ System.out.println("getMS return: " + n/om); return n/om; } private static int getLS(int n){ System.out.println("getLS return: " + n%10); return n%10; } private static String readInput(){ //Assume code for readInput method is include here } }
Background image of page 4
Question/Answer Sheet - Page 5 - COMPSCI 101 S2 C/T SURNAME: . ..................................................... FORENAMES: . .......................................................... CONTINUED (a) What is the output produced by the program when the user enters the number 4? Enter your answer in the box below. ( 5 marks ) (b) What is the output produced by the program when the user enters the number 34567? Enter your answer in the box below.
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 / 26

2003SCExamQuestions - COMPSCI 101 S2 C/T 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