954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help!Simple Program on Grades

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

redmaverick
Light Poster
35 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

The compiler gives an error about something being unbounded

redmaverick
Light Poster
35 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 
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.

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 
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.

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You