Solved

implementing Option handling : command line exception

Posted on 2004-09-06
5
224 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 92

Expert Comment

by:objects
ID: 11993889
0
 
LVL 18

Accepted Solution

by:
armoghan earned 50 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 72
JUnit 4 @Before and @BeforeClass differences 3 59
custom annotations 9 38
tomcat not starting 6 45
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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