- #1
zak100
- 462
- 11
Hi,
I am creating a netbeans application. I am trying to handle square root exception. If the argument to sqrt is positive it should display its result in the text area otherwise, it would display a message that square not possible. Its displaying the result. For instance if the argument is positive (i.e. 25) , it displays its result (i.e. 5) in the text area but if the argument is negative it displays "NaN" in the text area instead of "Square root of negative numbers not possible" . Following is my code:
strVal=tfValue.getText();
int val=Integer.parseInt(strVal);
try{
double res= Math.sqrt(val);
taResult.setText(" " + res);
}catch(ArithmeticException e){
taResult.setText("Square root of negative numbers not possible");
}Some body please guide me about this.Zulfi.
I am creating a netbeans application. I am trying to handle square root exception. If the argument to sqrt is positive it should display its result in the text area otherwise, it would display a message that square not possible. Its displaying the result. For instance if the argument is positive (i.e. 25) , it displays its result (i.e. 5) in the text area but if the argument is negative it displays "NaN" in the text area instead of "Square root of negative numbers not possible" . Following is my code:
strVal=tfValue.getText();
int val=Integer.parseInt(strVal);
try{
double res= Math.sqrt(val);
taResult.setText(" " + res);
}catch(ArithmeticException e){
taResult.setText("Square root of negative numbers not possible");
}Some body please guide me about this.Zulfi.