Skip to content
Sign upLog in
← Back to Community

how do I input "Square root of" Java?

Profile icon

How do input :
The square root of (vertical pixels^2+Horizontal pixels^2) in Java?

Profile icon
Profile icon

I am not sure if this is still relevant but you can check this article: this will help you understand SQRT,

Profile icon

Check these websites:-
These websites might help you now:-
Click here
Click here
They will teach you the step-by-step process of getting the output.

Hope this helps

Profile icon

You can use Math.sqrt() for that. BTW, to square a number, you have to use Math.pow(). ^ is reserved for XOR.

double verticalPixels // = ...; double horizontalPixels // = ...; System.out.println("Square Root of Positive Number: " + Math.sqrt(Math.pow(verticalPixels, 2) + Math.pow(horizontalPixels, 2));
Profile icon

hey there,

to input in java, you can do (I think): Scanner sc=new Scanner(;

here are some websites on input that can help you:

for the square root:
i found this:

The java.lang.Math.sqrt() returns the square root of a value of type double passed to it as argument. If the argument is NaN or negative, then the result is NaN. If the argument is positive infinity, then the result is positive infinity. If the argument passed is positive zero or negative zero then the result will be same as that of the argument.

from here:,the%20result%20is%20positive%20infinity.

read more: