import java.util.Scanner;
public class GradeCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter a score
System.out.print("Enter the score: ");
int score = scanner.nextInt();
// Determine the grade based on the score
String grade;
if (score >= 90 && score <= 100) {
grade = "A";
} else if (score >= 80 && score < 90) {
grade = "B";
} else if (score >= 70 && score < 80) {
grade = "C";
} else if (score >= 60 && score < 70) {
grade = "D";
} else if (score >= 0 && score < 60) {
grade = "F";
} else {
grade = "Invalid score";
}
// Print the grade
System.out.println("The grade is: " + grade);
scanner.close();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter