Skip to content
Sign upLog in
← Back to Community

how do I input "Square root of" Java?

Profile icon
Akosuaba25

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

Voters
Profile icon
Akosuaba25
Comments
hotnewtop
Profile icon
codebroken

I am not sure if this is still relevant but you can check this article: https://www.scaler.com/topics/square-root-in-java/ this will help you understand SQRT,

Profile icon
PattanAhmed

@Akosuaba25
Hi,
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.
Thanks!

Hope this helps

Profile icon
Coder100

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
Bookie0

hey there,

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

here are some websites on input that can help you:

https://www.javatpoint.com/how-to-get-input-from-user-in-java

https://www.w3schools.com/java/java_user_input.asp

https://www.programiz.com/java-programming/basic-input-output


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:
https://www.geeksforgeeks.org/java-sqrt-method-examples/#:~:text=Math.,the%20result%20is%20positive%20infinity.

read more:

https://www.edureka.co/blog/java-sqrt-method/

https://beginnersbook.com/2019/02/java-program-to-find-square-root-of-a-number-without-sqrt/

https://www.tutorialspoint.com/java/number_sqrt.htm