This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Command line argument passing  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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


 
Sheriff
Posts: 23647
49
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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: 21424
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 59782
188
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21424
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
Notepad PHP Windows
  • Mark post as helpful
  • send pies
  • 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]);

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!