The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the square java

Respuesta :

First of all, a bit of theory: since the area of a square is given by

[tex] A = s^2 [/tex]

where s is the length of the square. So, if we invert this function we have

[tex] s = \sqrt{A} [/tex].

Moreover, the diagonal of a square cuts the square in two isosceles right triangles, whose legs are the sides, so the diagonal is the hypothenuse and it can be found by

[tex] d = \sqrt{s^2+s^2} = \sqrt{2s^2} = s\sqrt{2} [/tex]

So, the diagonal is the side length, multiplied by the square root of 2.

With that being said, your function could be something like this:

double diagonalFromArea(double area) {

double side = Math.sqrt(area);

double diagonal = side * Math.sqrt(2);

return diagonal;

}