doubles, variables, functions Student approved
An old piece of math is the Pythagorean Theorem, which relates the lengths of the three sides of a right triangle: the sum of the two leg lengths, squared, is equivalent to the hypotenuse's length, squared: a^{2} + b^{2} = c^{2}
.
So if you know the length of each of the triangle's legs (a
, b
), the hypoteneus' length, c
, is square root[a^{2} + b^{2}]
Complete the calcHypotenous
function.
The function takes two double a
and double b
, which you'll want to use in the equation. Your function should
class Pythag{
public static void main(String[] args){
double hyp = calcHypotenuse(3, 4);
System.out.println(hyp);
}
static double calcHypotenuse(double a, double b){
double c = //something
return c;
}
}
5