Page 10 - KMK PREPSPM2 1819 ANSWER
P. 10
SULIT No. Matrik…………………………………….… No. Kad Pengenalan………………………….. SC015
(iii) Write a pseudocode to find the difference between two values; num1
and num2 in such a way that the difference will always be a positive
value.
[2 marks]
If num1 > num2
diff = num1 – num2
Else if num2 > num1
diff = num2 – num1
(iv) Write a pseudocode to swap two values, val1 and val2.
[2 marks]
temp = val1
val1 = val2
val2 = temp
2 (a) Java is a programming language that produces software for multiple platforms.
(i) Write two (2) ways to include comments “This is Java” in a Java
program.
[1 mark]
[1 markah]
//This is Java
/* This is Java */
(ii) Complete the given Java program to solve the problem statement
below.
“The table below shows the price per dozen for different grades of
eggs. Write a complete Java program to calculate and display the
price that a customer has to pay based on the grade and number of
eggs bought.”
Grade Price (RM) per dozen
A 4.50
B 3.50
C 2.90
[3 marks]
10 SULIT

