?
Solved

implementing Option handling : command line exception

Posted on 2004-09-06
5
Medium Priority
?
263 Views
Last Modified: 2010-03-31
Hi experts

I want to create a program that gets arguments from command line, and I would like to check for exceptions.

public static void main( args[] )
{
.......
}

for example,
All arguments must be int , or all must be between 'a' to 'z'.
The number of arguments must be 5, and 5th argument must be bigger than 4th, and so on.....
is there any ready made option handling class i can use?
I would appreciate if some one can show me some example code.
thanx

0
Comment
Question by:oldb
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
armoghan earned 100 total points
ID: 11993954
0
 
LVL 92

Expert Comment

by:objects
ID: 11993968
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11994221
For getting integer use
int firstArg;
firstArg = Integer.parseInt(args[0]);

for text having only alphabets use this function

public static boolean isLetter(String s)
{
for(int i = 0; i < s.length(); i++)
{
if(!Character.isLetter(s.charAt(i)))
{
return false;
}
}

return true;
}
 
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12041712
Thanx.
But can you pleae tell me the reason to give it a C grade?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question