class Grade  {
 
    public static void main (String args[])  {
       final int score = Integer.parseInt (args[0]);
       final char grade;
 
       if (score >= 90) {
          grade = 'A';
       } else if (score >= 80) {
           grade = 'B';
       } else if (score >= 70) {
           grade = 'C';
       } else if (score >= 60) {
           grade = 'D';
       } else {
           grade = 'F';
       }
       System.out.println ("The grade is " + grade + ".");
    }
 }

This is simple program is not being executed....I really dont know where I went wrong...

final char grade;

Declaring a variable as "final" is almost like making it a constant and hence its value cannot be changed later (which you are doing in the "if else" blocks.

final char grade;

Declaring a variable as "final" is almost like making it a constant and hence its value cannot be changed later (which you are doing in the "if else" blocks.

I guess I was wrong on that call, I had the opinion that you need to specify the value for the "final" variables during declaration itself, but when I compiled and ran the code I got the output:-

stephen@steve:~/Development/java/daniweb> java Grade 61
The grade is D.
stephen@steve:~/Development/java/daniweb>

So I guess the only problem is as stultuske suggested, you are not specifying the command line argument of marks correctly.

This article has been dead for over six months. Start a new discussion instead.