Java Program to Calculate Grade of Students

« Previous Program Next Program »

Calculate Grade of Students in Java

To calculate the grade of a student on the basis of his/her total marks in Java programming, you have to ask to the user to enter the marks obtained in some subjects (5 subjects here), then calculate the percentage and start checking for the grades to display the grade on the output screen.

Java Programming Code to Calculate Grade

Following program ask to the user to enter the marks obtained in 5 subjects to calculate and display the grade of student:

/* Java Program Example - Calculate Grade of Student */
import java.util.Scanner;

public class JavaProgram
    public static void main(String args[])
        int mark[] = new int[5];
        int i;
        float sum=0, avg;
        Scanner scan = new Scanner(;
        System.out.print("Enter Marks Obtained in 5 Subjects : ");
        for(i=0; i<5; i++)
            mark[i] = scan.nextInt();
            sum = sum + mark[i];
        avg = sum/5;
        System.out.print("Your Grade is ");
        else if(avg>60 && avg<=80)
        else if(avg>40 && avg<=60)

When the above Java Program is compile and executed, it will produce the following output:

Java Program calculate grade of student

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

« Previous Program Next Program »

Latest 5 Posts by CodesCracker


Quick Links
Signup - Login - Give Online Test