Java If Else Test Grade Program

By | July 12, 2019

Task: Java If Else Test Grade Program – Write a Java program to input test score of a student and show the grade according to the given criteria:

  1. test scores 90 or more , ‘A’ grade
  2. test scores 80 or more, ‘B’ grade
  3. test scores 70 or more, ‘C’ grade
  4. test scores 60 or more, ‘D’ grade
  5. test scores Below 60,  ‘A’ grade
  6. test scores >= 90, ‘F’

The Source Code of If else if Java Test Grade Program

/*
 * Write a Java program to input test score 
of a student and then show grade according 
to the following criteria:
Grade A for scores 90 or more
Grade B for scores 80 or more
Grade C for scores 70 or more
Grade D for scores 60 or more
Grade F for scores BELOW 60
 */
package testgrade;

import java.util.Scanner;

/**
 * @author www.EasyCodeBook.com (c)
 */
public class TestGrade {

    public static void main(String[] args) {

        int score;
        char grade;
        Scanner input = new Scanner(System.in);
        System.out.print("Enter Test Score of a Student:");
        score = input.nextInt();
        
        if (score >= 90)  
            grade = 'A'; 
         else if (score >= 80) 
            grade = 'B'; 
         else if (score >= 70)  
            grade = 'C'; 
         else if (score >= 60)  
            grade = 'D'; 
         else 
            grade = 'F'; 
         
        System.out.println("According to "+score+" Grade is: " + grade); 
    
        
    }
    
}

The output:

Enter Test Score of a Student:92
According to 92 Grade is: A

Another sample run:
Enter Test Score of a Student:56
According to 56 Grade is: F

Loading

Leave a Reply

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