Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Displaying Text in the Text Area

Zulfi KhanSep 4 2016 — edited Sep 5 2016

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.

This post has been answered by unknown-7404 on Sep 4 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2016
Added on Sep 4 2016
3 comments
825 views