• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Command line argument passing

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to build this if-else by passing a command line arguament to the variable gpa.but i get an error. can someone help me please with this problem. thank you


 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you notice anything about the error when it happened? I ask because "I get an error" isn't very helpful information. It tells us nothing about your problem.

So what you should do is, when the error occurs, look at it. Error messages are designed to provide information to help the programmer fix the error, so by ignoring the error message you are throwing away valuable information.

If you still can't solve the problem after doing that, then tell us what the error is. And don't just post a vague paraphrase of the error message, copy and paste the actual error message.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see your private messages for an important administrative matter.

/Dave
 
MohamedSalim malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah thank you for advice. : I tried to pass the argument to the variable using command line. i tried in various ways . but still this error occurs.. This is the error message occured when i try to compile the program.
E.java:3: ';' expected
double gpa(args[0]);
^
E.java:3: not a statement
double gpa(args[0]);
^
E.java:3: ';' expected
double gpa(args[0]);
^
3 errors
 
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is gpa?What are you doing? Is gpa a method or double Variable ??, put code tags and format you code.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

MohamedSalim malik wrote:double gpa(args[0]);


I think you're trying to convert args[0] into a double. Well, this is not the way. You can't convert anything into a double by just adding wrapping it in parentheses directly after the variable name. The only way to give any variable a value is still with the assignment operator: You'll be able to find that something on the Javadoc page of java.lang.Double. Check for a static method that takes a String and returns a double.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought, maybe he's not come across the code tags yet, so I'll add them to the original post. Unfortunately, that simply shows awkward indentation. You should indent multiple if elses like thisYou should also spell better than I do
 
MohamedSalim malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rob Spoor .. yeah that the point where i did the mistake. i didnt convert the string value to a double. then i corrected the source code, and it did work.. :

class E{
public static void main(String args[]){
double gpa=Double.parseDouble(args[0]);
if(gpa>=3.6)
{
System.out.println("First class");
}

else if(3.59>=gpa && gpa>=3.4)
{
System.out.println("Upper Second class");
}

else if(3.49>=gpa && gpa>=3.00)
{
System.out.println("Lower second class");
}

else if(2.99>=gpa && gpa>=2.00)
{
System.out.println("Pass");
}
else
{
System.out.println("Fail");
}
}
}
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome. For your information, the other primitive wrapper classes have similar methods: Integer.parseInt, Byte.parseByte, etc.
 
Greenhorn
Posts: 14
PHP Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The command line argument passess a string value so you have to convert that into Double to proceed with calculation. Double.parseDouble method is used to do the above convertion.(Wrapper classess)

use following
double gpa=Double.parseDouble(args[0]);

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic