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...

Recommended Answers

All 5 Replies

The compiler gives an error about something being unbounded

Please provide full error message, also post move to Java section....

are you sure you passed a parameter in your run command prompt when you run the prog?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.