The Java Program: Grade.java

  1 // Grade.java -- A Java program illustrating "if"
  2 
  3 public class Grade  {
  4 
  5    public static void main (String args[])  {
  6       final int score = Integer.parseInt (args[0]);
  7       final char grade;  // "blank final"
  8 
  9       if (score >= 90) {
 10           grade = 'A';
 11       } else if (score >= 80) {
 12           grade = 'B';
 13       } else if (score >= 70) {
 14           grade = 'C';
 15       } else if (score >= 60) {
 16           grade = 'D';
 17       } else {
 18           grade = 'F';
 19       }
 20 
 21       // N.B.  All cases must be handled or analysis would yield
 22       // an error: "Variable grade may not have been initialized."
 23 
 24       System.out.printf ("The grade is %c.%n", grade);
 25    }
 26 }
 27