Challenge: Grade Calculator

Lab Java Beginner 10 points

Read marks (0 to 100) and print the grade:

  • 90 and above: A
  • 75 to 89: B
  • 50 to 74: C
  • below 50: F

Input

One whole number from 0 to 100.

Output

One letter.

Example

Input

95

Output

A
Sample input available Sample output available
Editor
Java

Hints

Check the highest grade first.

Use else if so only one grade is printed.

Solution explanation

Because Java stops at the first true condition, ordering from highest to lowest keeps each check simple.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int marks = sc.nextInt();
        if (marks >= 90) {
            System.out.println("A");
        } else if (marks >= 75) {
            System.out.println("B");
        } else if (marks >= 50) {
            System.out.println("C");
        } else {
            System.out.println("F");
        }
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD