简体   繁体   中英

How can I incorporate a square root function into this calculator I am trying to make?

I am currently making a simple calculator, and I want to incorporate the square root function into it, currently my code looks like this, but it does not work:

if ("√x".equals(operator))
{
double sqrt = Math.sqrt(num1);
}    

Here Num 1 is the input number, but I am not able to find or come up with code that would √x.

I think Math.sqrt(num1); should work quite good. I suppose you later use the variable 'sqrt', are you sure you are returning it whenever it's needed?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM