Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help with Math.tan and Math.atan

1. ## 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:

```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();
double par2 = in.nextDouble();

System.out.println("calculating...");
double deci = Math.tan(par1 / par2);
System.out.println("The answer is: " + Double.toString(deci));
}
}```  Reply With Quote

2. ## 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.  Reply With Quote

3. ## 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.  Reply With Quote

4. ## Re: Help with Math.tan and Math.atan 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.  Reply With Quote

5. ## 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.  Reply With Quote

6. ## 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:

```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();
double par2 = in.nextDouble();

System.out.println("calculating...");
double deci = par1 / par2;  Reply With Quote
7. ## Re: Help with Math.tan and Math.atan  Reply With Quote 