Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: Using Loops in place of Exception Handlers
|
Posted: Mar 8, 2004 3:31 PM
|
|
Very similar to your code, but I prefere it that way :
String numbers = "0123456789";
boolean allNumeric = true;
char letter;
for(int i = 0; i < args[1].length(); i++)
{
letter = args[1].charAt(i);
if ( numbers.indexOf (letter) == -1)
{
allNumeric = false;
break; // Must break otherwise it is only the result of the last check
// that will be taken into account !
}
}
if(allNumeric)
{
//do the arithmetic
} else
{
//tell user that one of the arguments contains non-numeric characters.
}
//repeat for the following argument in a 'bigger' loop
Cheers,
\T,
|
|