Code:
import java.util.Scanner; public class Grades { public static void main(String[] args) { char grades[] = {'F','D','C','B','A'}; System.out.print("Enter final class average: "); // Read in final class average Scanner in = new Scanner(System.in); double average = in.nextDouble(); char grade = grades[(int)Math.min(4,Math.max(0,((average-1)/10)-5))]; System.out.println("Grade: " + grade); } }
Output:
$ java Grades Enter final class average: 98 Grade: A $ java Grades Enter final class average: 71 Grade: C $ java Grades Enter final class average: 82 Grade: B