on 04-19-2009 4:07 PM
if Blank or non numeric or other than 1,3,12,13
raise error
Thanks in Advance
He praveen,
prasanna code will works fine,still u struck with this issue??
regards,
raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Praveen,
You can use the following condition to check all the 3 constraints.
Input String 'a'.
if( a.length()!=0 && !a.matches("\[0-9\]") &&
(a.equals("1") || args[0].equals("12") ||args[0].equals("13"))){
return a
}else{
throw new RuntimeException("Your Exception");
}
(or)
if( a.length()!=0 && a.matches(" \ \ d*") &&
(a.equals("1") || args[0].equals("12") ||args[0].equals("13"))){
return a
}else{
throw new RuntimeException("Your Exception");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Additionally, to check for non numeric, use the following code.
try
{
int i = Integer.parseInt(inputSTR)
}
catch(NumberFormatException n)
{
throw new RuntimeException("Number Format Exception");
}
Hope this helps.
Thanks and Regards,
Kalpesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Praveen,
Since you need only 1,3,12,13 to be passed successfully, you can use the below code.
input -a
if(a.equals("1") || a.equals("3") || a.equals("12") ||a.equals("13"))
{
return a;
}
else
{
throw new RuntimeException("Your Error exception");
}
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.