import java.util.Scanner; public class GradeCalculator { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter the percentage obtained by the student:"); double percentage = sc.nextDouble(); char grade; if (percentage >= 90) { grade = 'A'; } else if (percentage >= 80) { grade = 'B'; } else if (percentage >= 70) { grade = 'C'; } else if (percentage >= 60) { grade = 'D'; } else if (percentage >= 50) { grade = 'E'; } else { grade = 'F'; } switch (grade) { case 'A': System.out.println("Grade: A - Excellent"); break; case 'B': System.out.println("Grade: B - Very Good"); break; case 'C': System.out.println("Grade: C - Good"); break; case 'D': System.out.println("Grade: D - Satisfactory"); break; case 'E': System.out.println("Grade: E - Sufficient"); break; case 'F': System.out.println("Grade: F - Fail"); break; default: System.out.println("Error: Invalid grade"); } sc.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