Page 13 - KMK PREPSPM2 1819 ANSWER
P. 13

SULIT     No. Matrik…………………………………….… No. Kad Pengenalan…………………………..  SC015



                                                                                                [2 marks]
                                      Area=6.0
                                      Area=24.0


                              (ii)   Explain three (3) types of programming errors.
                                                                                                [3 marks]
                                         Types of                         Explanation
                                           Error
                                                      Occurs when the syntax of the programming
                                      Syntax Error    language is violated.
                                                      Missing semicolons
                                                      Occurs when a program with no syntax errors asks
                                                      the computer to do something that the computer is
                                      Run-time        unable to reliably do.
                                      Error
                                                      Trying to divide by a variable that contains a value
                                                      of zero

                                                      Occurs when there is a design flaw in your program.
                                      Logic Error
                                                      Adding when you should be subtracting

                              (iii)   Complete the given Java program to solve the following problem.
                                            “Calculate and display grade for 100 students based on
                                            marks.”
                                                 Marks                Grade
                                                80 – 100                A
                                                60 – 79                 B
                                                40 – 59                 C
                                                 0 – 39                 F
                                                                                                [6 marks]
                                      import java.util.Scanner;
                                      class MarkGrade{
                                         public static void main(String[] args){
                                            Scanner sc=new Scanner(System.in);
                                            double mark;
                                            char grade=' ';
                                            for(int i=0;i<3;i++){
                                               mark=sc.nextDouble();
                                               if(mark>=80)
                                                  System.out.println('A');
                                               else if(mark>=60)
                                                  System.out.println('B');
                                               else if(mark>=40)
                                                  System.out.println('C');
                                               else
                                                  System.out.println('F');
                                            }
                                         }
                                      }




                                                           13                                SULIT
   8   9   10   11   12   13   14   15   16