Menu
Topics Index
...
`

Print Student Grade - Java Example Program


Print Student Grade
class PrintStudentGrade
{
    public static void main(String arg[])
    {
        int marks = 65;
        
        if( marks > 75 )      // CONDITION A
        {
            System.out.println("Distinction"); // LINE A
        }
        else if( marks > 60 ) // CONDITION B
        {
            System.out.println("First Class"); // LINE B
        }
        else if( marks > 50 ) // CONDITION C
        {
            System.out.println("Second Class"); // LINE C
        }
        else
        {
            System.out.println("Fail");  // LINE D
        }
    
    }
}
OUTPUT

First Class

DESCRIPTION

Since the marks are 65, the CONDITION A will be false, so the CONDITION B in the else is executed. Since CONDITION B is true, LINE B is executed printing First Class.

THINGS TO TRY
  • Change the marks to 75, 53 and 32 and see the output in each case.
  • Try removing the else conditions and see the result with various values.
  • Change the program to achieve the same functionality with out using the else block.

© meritcampus 2019

All Rights Reserved.

Open In App