Input mark and print grade in Java
if else if - Question 10
In this question, we will see how to input mark obtained in English subject in an examination and print the grades accordingly in Java programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q10) Write a program in Java to input mark obtained in English subject in an examination and print the grades accordingly.
Marks in English | Grade |
90 or above | A |
70 to 89 | B |
50 to 69 | C |
40 to 49 | D |
Below 40 | F |
Program
import java.util.Scanner;
public class Q10
{
public static void main(String args[])
{
int e;
Scanner sc=new Scanner(System.in);
System.out.print("Enter marks obtained in English subject ");
e=sc.nextInt();
if(e>=90)
{
System.out.print("Grade = A");
}
else if(e>=70 && e<=89)
{
System.out.print("Grade = B");
}
else if(e>=50 && e<=69)
{
System.out.print("Grade = C");
}
else if(e>=40 && e<=49)
{
System.out.print("Grade = D");
}
else
{
System.out.print("Grade = F");
}
}
}
Output
Enter marks obtained in English subject 68 Grade = C