CS1020: Data Structures and Algorithms I 1.

60 downloads 216 Views 283KB Size Report
CS1020: Data Structures and Algorithms I. Tutorial 1: Java and Simple OOP. ( Week starting 25 August 2013). 1. [Basic Concept and OOP] a) Match the terms in  ...
CS1020: Data Structures and Algorithms I Tutorial 1: Java and Simple OOP (Week starting 25 August 2013) 1. [Basic Concept and OOP] a) Match the terms in the left column to their corresponding definitions/functionalities in the right column: A. B. C. D. E. F. G.

Class An Object Identifier Variable Method Parameter Constructor

1. 2. 3. 4. 5. 6. 7.

Create a new object instance and initialize the instance variable A name given to a package, class, interface, method, or variable Store data in a program User defined data type A value that is passed to the method Function, or procedure Instance of a class

Answers: A – 4, B – 7, C – 2, D – 3, E – 6, F – 5, G - 1

1.

b) The function below is intended to find prime number. Find what is wrong with the code and correct the mistake. /* Precondition: num can be any number Postcondition: true if num is prime false otherwise */ public static bool isPrime(int num) { for(int i=0; i