04/03/2023

Java Program to Find Grade of a Student Using Switch Case

Find Grade Using Switch Case in Java: A university conducts a 100-mark exam for its student and grades them as follows. assigns a grade based on the value of the marks. write a java program to print the grade according to the mark secured by the student. [use switch-case]. Write a java program to find out students' grades using a switch case.

Java Program to Find Grade of a Student Using Switch Case

Logic is very simple for grade programs in Java using a switch case. Taking input from the user(Input should be between range given 0 to 100 Else program play with you), as we know the grading system so divides the Mark by 10 and put the case condition in the program See the below Explanation Step by step for better understanding.

Java Program to Find Grade of a Student Using Switch Case


import java.util.Scanner;

/* write a java program to accept the marks of a student and then display the grades using a switch case conditional statement.*/

class grade {
	static Scanner sc = new Scanner(System.in);

	public static void main(String args[]) {

		int marks;

		/*This Is a Grade Checker Program*/
		while (true) {
			System.out.print("\n=========================================");
			System.out.print("\nThis is program find out students grades");
			System.out.print("\n-----------------------------------");
			System.out.print("\nEnter The Marks Between 0 To 100:");
			System.out.print("\n=========================================\n");

			System.out.print("\nEnter The Mark: ");
			marks = sc.nextInt();

			if (marks > 100) {
				/* Marks greater than 100 */
				System.out.print("\nDon't Be Smart Enter your Marks Between Limit\n");
			} else {
				switch (marks / 10) {
					case 10:
					case 9:
						/* Marks between 90-100 */
						System.out.print("\n=============================");
						System.out.print("\nYour Grade Is: A or Excellent");
						System.out.print("\n=============================");
						break;
					case 8:
					case 7:
						/* Marks between 70-89 */
						System.out.print("\n=============================");
						System.out.print("\nYour Grade Is: B or Very Good");
						System.out.print("\n=============================");
						break;
					case 6:
						/* Marks between 60-69 */
						System.out.print("\n========================");
						System.out.print("\nYour Grade Is: C or Fair");
						System.out.print("\n========================");
						break;
					case 5:
					case 4:
						/* Marks between 40-59 */
						System.out.print("\n========================");
						System.out.print("\nYour Grade Is: D or Pass");
						System.out.print("\n========================");
						break;
					default:
						/* Marks less than 40 */
						System.out.print("\n================================================");
						System.out.print("\nYou Grade Is: F or Fail\n");
						System.out.print("\nSuggetin: Do Not show your Sheet to Your Parent");
						System.out.print("\n================================================");
				}
			}
		}
	}
}

Student Grades Using Switch Case Explanation


So first divide the mark by 10 so we can get a reminder and as you can see in the program we use case 4 to case 10. So if the remainder is between 4 to 10 our case performs the particular grade operation and displays the result See the Step By Step Example for each case that may be in this grade problem.

Case 1: If the user is Over smart then there is a condition that if the mark given by the user is greater than 100 then our program displays the Message "Don't Be Smart Enter your Marks Between Limit" or else perform the Else part.

Enter the Mark: 1000
Output: Don't Be Smart Enter your Marks Between Limits.

Case 2: If the user is entering the marks between 0 to 100 and then a particular grade portion will be executed and display the output in the Console screen.

Enter the Mark: 95
Output: Your Grade Is: A or Excellent

This operation performs the same for Grades B, C, and D.

Case 3: If Enter marks are not fulfilled the requirement of the case then the program will perform the default case.

Enter the Mark: 25
Output: Your Grade Is: F or Fail

Also, see the program suggestion " Do Not show your Sheet to Your Parent "

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: