Help with Math.tan and Math.atan

I am pretty new to math and wanted to find out how to calculate the angle between the hypotenuse and the adjacent side, with only knowing the adjacent side and the abutting catheter.

I know that tan is abutting catheter divided by adjacent side. But that gives my a double.

How to I cast that number to degrees.

Here's my code:

Code java:

import java.util.Scanner;
public class Matte {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter abutting catheter: ");
double par1 = in.nextDouble();
System.out.println("Enter adjacent side: ");
double par2 = in.nextDouble();
System.out.println("calculating...");
double deci = Math.tan(par1 / par2);
System.out.println("The answer is: " + Double.toString(deci));
}
}

**Please help me!**

Re: Help with Math.tan and Math.atan

Hello Dr Code!

What is returned by the **tan** method? I know it's a *double* but what is the unit of measurement? Is it radians? If so, there is a toDegrees method in the **Math** class which is converting radians to degrees.

Re: Help with Math.tan and Math.atan

That's the problem, I have no idea what it returns, but I will try the toDegrees method.

Re: Help with Math.tan and Math.atan

Quote:

Originally Posted by

**Dr.Code**
That's the problem, I have no idea what it returns, but I will try the toDegrees method.

It won't work.

From the API, the **tan(double a)** method *Returns the trigonometric tangent of an angle*. Therefore it should be measured as length (mm, cm, etc) - if I'm not mistaken.

And also it takes one parameter: *a - an angle, in *__radians__.

Are you passing the method a parameter in radians?

Hope this helps.

Re: Help with Math.tan and Math.atan

Well what I'm trying to do is to calculate an angle with only knowing the abutting catheter and the adjacent side.

I do not know how to do that. I think it is something with arctan(Math.atan()), but don't know what.

Re: Help with Math.tan and Math.atan

Wait, solved it, I should use Math.atan instead of tan and then convert the radians i get from that to degrees. And I get the correct output.

Here's my final code:

Code java:

import java.util.Scanner;
public class Matte {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter abutting catheter: ");
double par1 = in.nextDouble();
System.out.println("Enter adjacent side: ");
double par2 = in.nextDouble();
System.out.println("calculating...");
double deci = par1 / par2;
double radians = Math.atan(deci);
double degrees = Math.toDegrees(radians);
long answer = Math.round(degrees);
System.out.println("The answer is: " + Long.toString(answer) + " degrees.");
}
}

Re: Help with Math.tan and Math.atan

Glad you got it work. Make sure you mark the thread as solved.