{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2002SCTestQuestions

# 2002SCTestQuestions - COMPSCI 101 THE UNIVERSITY OF...

This preview shows pages 1–8. Sign up to view the full content.

COMPSCI 101 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2002 Campus: City and Tamaki COMPUTER SCIENCE TEST Principles of Programming (Time allowed: 75 minutes) 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 Laboratory Day and Time Question Marks Out of Question 1 (Primitive Types) 15 Question 2 (Strings) 10 Question 3 (If statements) 10 Question 4 (Assignment 02) 10 Question 5 (Assignment 02) 10 Question 6 (Loops) 8 Question 7 (Arrays) 12 Question 8 (Classes) 15 Question 9 (Frames) 10 Total 100

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

View Full Document
Candidate's Name:___________________ 2 COMPSCI 101 This page is left blank
Candidate's Name:___________________ 3 COMPSCI 101 1. What is the output for each of the following statements? (a) System.out.println( 1 + 2 + "3" + "4" + 5 + 6); (3 marks) (b) System.out.println( 2/3 + 3.0/2.0 + " " + 2/3 + 3.0/2.0); (3 marks) (c) System.out.println( 5%10 + " " + 10%3 ); (3 marks) (d) System.out.println( 1* 2+3 %4 +5/ 6+1.0 ); (3 marks) (e) System.out.println( "\"+"+"\"+"\n^\\Test\\" ); (3 marks)

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

View Full Document
Candidate's Name:___________________ 4 COMPSCI 101 2. Write a method called removeLetter which accepts a String s and an integer i as parameters. Your method should remove a single character from the String passed as a parameter, and it should return the String with the character removed. The character which is to be removed is located at the index specified by i . Example: Executing the statements: System.out.println( removeLetter( "Hello", 0 ) ); System.out.println( removeLetter( "Hello", 1 ) ); System.out.println( removeLetter( "Hello", 2 ) ); would produce the output: ello Hllo Helo You can assume that the integer passed to the method as the index will be a valid index value (e.g. it will be in the range 0 … length-1). Write your method below. (10 marks)
Candidate's Name:___________________ 5 COMPSCI 101 3. What is the output of each of the following code fragments? (a) System.out.println( 23==34 || 3==3); (2 marks) (b) System.out.println( 1!=2 && !(3==3) || 2==2 ); (2 marks) (c) int a = 4; int b = 4; int c = 2; if( a==b ) if ( b<c ){ if ( c>a ) System.out.println( "First" ); } else System.out.println( "Second" ); else System.out.println( "Third" ); System.out.println( "Fourth" ); (2 marks) (d) int a = 0; int b = 3; if( !(a<b) || (a!=b && b==3) ) System.out.println( a ); if( ! (a<b || a!=b && b==3) ) System.out.println( b ); System.out.println("done");

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

View Full Document
Candidate's Name:___________________ 6 COMPSCI 101 (4 marks)
Candidate's Name:___________________ 7

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 18

2002SCTestQuestions - COMPSCI 101 THE UNIVERSITY OF...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online