Java Math.sqrt is not working

Here is my code look like:

SquareRoot = (Button)findViewById(R.id.SquareRoot);
        SquareRoot.setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
                x = TextBox.getText();
                xconv = Double.parseDouble(x.toString());
                Math.sqrt(xconv);
                answer = Double.toString(xconv);
                TextBox.setText(answer);

        }});

Math.sqrt() returns the new value, which needs to be assigned to a variable. So, xconv = Math.sqrt(xconv) or TextBox.setText(Double.toString(Math.sqrt(xconv))).

5 Likes

Replace this: xconv = Double.parseDouble(x.toString()); with this xconv = Math.sqrt(xconv);

you can check this article on SQRT.

1 Like

this is also a right solution @ Soham1087

1 Like