Page 5 - KMK PREPSPM2 1819 ANSWER
P. 5
SULIT No. Matrik…………………………………….… No. Kad Pengenalan………………………….. SC015
(ii) Value
[1 mark]
Value is actual data stored in the array elements
(c) Write a Java code segment to perform the following tasks:
(i) Declare an array named marks and names of type double and
String respectively.
[1 mark]
double[] marks;
String[] names;
(ii) Declare and initialize the array named scores of four (4) elements
such that first element is initialized to 97.5, second element is
initialized to 41.8, third element is initialized to 36.5 and last element
is initialized to 78.6.
[1 mark]
double[] scores={97.5,41.8,36.5,78.6};
(iii) Declare and create array named marks to store 100 students’ marks.
[1 mark]
double[] marks=new double[100];
(iv) Calculate the sum of all elements in the array that you have created in
question 3(c)(ii).
[2 marks]
for(int i=0;i<scores.length;i++)
sum=sum+scores[i];
(v) Display all elements in the array scores that you have created in
3(c)(ii).
[1 mark]
for(int i=0;i<scores.length;i++)
System.out.print(scores[i]);
5 SULIT

