Java Program to Calculate Grade of Students

  • Java Program to find the grade of a student, given the marks of N subjects.

Given the marks of N subjects, we have to print the grade of a student based on the following grade slab.

  • If Percentage Marks > 90, Grade is A+
  • If 70 <= Percentage Marks <= 89, Grade is A
  • If 60 <= Percentage Marks <= 69, Grade is B
  • If 50 <= Percentage Marks <= 59, Grade is C
  • If Percentage Marks <= 40, Grade is D

In this java program, we first ask user to enter number of subjects and store it in variable "count". Then using a for loop, we take marks of "count" subjects as input from user and add them to variable "totalMarks". Then we find the percentage marks of student using following expression assuming each subject is of 100 marks.

percentage = (totalMarks/(count*100)) * 100;

Using a switch case, we check the grade of the student as per the slab mentioned above and print it on screen.

Java program to calculate the grade of a student


import java.util.Scanner;

 * Java Program to print grade of a student
public class StudentGrade {
    public static void main(String[] args) {
        int count, i;
        float totalMarks = 0, percentage, average;
        Scanner scanner;
        scanner = new Scanner(;

        System.out.println("Enter Number of Subject");
        count = scanner.nextInt();

        System.out.println("Enter Marks of " + count + " Subject");
        for (i = 0; i < count; i++) {
            totalMarks += scanner.nextInt();
        System.out.println("Total MArks : " + totalMarks);
        // Each subject is of 100 Marks
        percentage = (totalMarks / (count * 100)) * 100;

        /* Printing grade of a student using switch case statement */
        switch ((int) percentage / 10) {
        case 9:
            System.out.println("Grade : A+");
        case 8:
        case 7:
            System.out.println("Grade : A");
        case 6:
            System.out.println("Grade : B");
        case 5:
            System.out.println("Grade : C");
            System.out.println("Grade : D");
Enter Number of Subject
Enter Marks of 5 Subject
45 69 53 58 62
Total MArks : 287.0
Grade : C

Recommended Posts
Java Program to Calculate Average and Percentage Marks
Java Program to Calculate Arithmetic Mean of N Numbers
Java Program to Find LCM and GCD of Two Numbers
Java Program to Add Subtract Multiply and Divide Two Numbers
Java Program to Find Largest of Three Numbers
Java Program to Make a Simple Calculator using Switch Statement
Java Program to Calculate Simple Interest
Java Program to Calculate Compound Interest
Java Program to Check If a Year is Leap Year or Not
Java Program to Convert Celsius to Fahrenheit
Java Program to Convert Fahrenheit to Celsius
All Java Programs