Challenge: Grade Calculator
Completed
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
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
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module