In the previous article, we have seen Java Program to Calculate Compound Interest
In this article we are going to see how to calculate grade based on marks using Java programming language.
Java Program for Grade Calculation System
This is a simple program which can be implemented easily using if-else statements.
For example, let us consider the following grade system
- 100 – 80 grade = “A”
- 80 – 70 grade = “B”
- 70 – 60 grade = “C”
- 60 – 50 grade = “D”
- <50 grade = “F”
Approach:
- Create Scanner class object.
- Take user input for the obtained marks.
- Define a method
findGrade()
to find the grade of the student. - Use if-else ladder as shown in the program below to find the corresponding grade as per the given grade system.
Program:
import java.util.Scanner; public class Main { public static void main(String[] args) { // create scanner class object Scanner sc = new Scanner(System.in); // prompt user to enter his/her mark System.out.print("Enter your mark: "); int mark = sc.nextInt(); // display grade System.out.println("Your grade is " + findGrade(mark)); } public static String findGrade(int mark) { String grade; if (mark >= 80) grade = "A"; else if (mark >= 70) grade = "B"; else if (mark >= 60) grade = "C"; else if (mark >= 50) grade = "D"; else grade = "F"; return grade; } }
Output: Enter your mark: 78 Your grade is B
Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output
Related Java Programs: