Java program to calculate grade of students

In this post, we will see how to calculate grade of students in java.

Student’s grade is decided by average of marks.It is good program to practice execution of if statements in java.

Here is simple program to calculate grade of students

package org.arpit.java2blog;

import java.util.Scanner;

public class GradeCalculation
{
	public static void main(String args[]){
		int markArr[] = new int[5];
		int i;
		float total=0, avg;
		Scanner scanner = new Scanner(System.in);

		System.out.print("Enter Marks for 5 Subjects : ");
		for(i=0; i < 5; i++){ 
			markArr[i] = scanner.nextInt(); 
			total = total + markArr[i]; 
		} 

		avg = total/5; 
		System.out.print("Student's Grade is "); 
		if(avg > 80){
			System.out.print("A");
		}else if(avg > 60 && avg<=80){ 
			System.out.print("B"); }
		else if(avg > 40 && avg <= 60){
			System.out.print("C");
		} else{
			System.out.print("D");
		}
		scanner.close();
	}
}

Output:

Enter Marks for 5 Subjects : 50 60 70 80 90
Student’s Grade is B

That’s all about how to calculate grade of students in java.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.