Page 4 - KMK PREPSPM2 1819 ANSWER
P. 4
SULIT No. Matrik…………………………………….… No. Kad Pengenalan………………………….. SC015
(b) Identifiers are the names of variables, classes, methods, packages, and
interfaces. All identifiers must begin with letters, dollar sign ($) or underscore
(_).
(i) Explain variables and constant.
[3 marks]
Identifiers Explanation Example of Declaration
A location in the
Variable computer’s memory int total;
to store a value.
An identifier with a
value that cannot be
Constant final int MIN_WEIGHT = 50;
changed during
normal execution.
(ii) Identify the most suitable primitive data types for the following
situations.
a. To store the gender of a student whether M (for male) or F (for
female).
[1 mark]
char
b. Used to perform logical operations, most commonly to determine
whether some condition is true.
[1 mark]
boolean
c. To store age and number of siblings of a student.
[1 mark]
int
d. To store the value of an average of five marks entered by a user.
[1 mark]
double
3 An array consists of its data type, size, index, and value. All arrays start from index 0
to number of elements n minus 1 (n-1). We use an array when the data size is bigger.
All elements in an array consists of the same data type.
(a) Define array.
[1 mark]
An array is an ordered indexed collection of data values of the same type.
(b) Define the following terms in an array.
(i) Index
[1 mark]
The address for the array elements starting from 0 to n-1 where n is
the size of the array.
4 SULIT

