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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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:
Student’s Grade is B
That’s all about how to calculate grade of students in java.