preUPS 2 SET 3
preUPS 2 SET 3
(i). 1Malaysia
(ii). UPS 2
(b) Give one (1) reason why keywords such as true, else, and import
cannot be used as an identifier.
[1 mark]
_______________________________________________________________
2. Identify the most suitable data type to be used based on the given statement.
[2 marks]
(a) To store the average of 50 marks entered by a lecturer.
_______________________________________________________________
(b) To store the gender of a student.
_______________________________________________________________
3. Given the following declaration:
int y;
What is the value stored in variable y after the following statements are executed?
[2 marks]
(a) y = 40/100;
_______________________________________________________________
(b) y = 20%40;
_______________________________________________________________
4. Identify the type of operators based on the given Java Expressions.
[2 marks]
1 int x = 10;
2 int y = 3;
3 int z = 0;
4 int ans1 = x / y;
5 int ans2 = x / z;
(b) State and describe the type of programming error mentioned in 6(a).
[2 marks]
____________________________________________________________________
FIGURE 1
Write Java statement(s) to accomplish the following based on an array shown in
FIGURE 1.
(a) Declare and create the given array.
[1 mark]
_______________________________________________________________
(b) Display the difference between the fourth and fifth elements.
[1 mark]
_______________________________________________________________
(c) Assign the value 65 to the third element in the array.
[1 mark]
_______________________________________________________________
9. Answer the following question based on the given Java segment.
(a) Complete the given for statement to read both quiz1 and quiz2 marks for all
students into a respective array.
[2 marks]
for (int i=0; i<student.length; i++)
{
_________________________________________________________
_________________________________________________________
_________________________________________________________
}
(b) Write a Java statement (s) to calculate the average mark for each student and
assign it to the corresponding array.
[2 marks]
_______________________________________________________________
_______________________________________________________________
10. Consider the program segment as below. Write the first and last output.