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:
- test scores 90 or more , ‘A’ grade
- test scores 80 or more, ‘B’ grade
- test scores 70 or more, ‘C’ grade
- test scores 60 or more, ‘D’ grade
- test scores Below 60, ‘A’ grade
- 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