tags:

views:

387

answers:

6
+1  Q: 

Find sine in Java

Can anyone give me a quick tip?

For example....how would I find the sine of 90 degrees?

A: 

Look at the java.lang.Math class.

Michael Borgwardt
+3  A: 

You could use the Math.sin function where the argument is given in radians. Example:

double result = Math.sin(Math.PI / 3.0);
Darin Dimitrov
Thanks! so Math.sin(90) should do it.
relyt
No, it won't do it. The argument should be in radians. `Math.sin(Math.PI / 2)` should work.
Darin Dimitrov
No it's in radians... so 90 deg = PI/2 rad
pjp
Ah. Ok. Got it.
relyt
+1  A: 

http://java.sun.com/j2se/1.6.0/docs/api/java/lang/Math.html

It has a sin(double) method among other mathematical functions. It takes the angle in radian, so you'd have to do the conversion from degree. For that purpose (and others), Math also has the PI constant.

polygenelubricants
A: 

use

Math.sin(Math.toRadians(90))
Lucas
-1 as mentioned in other comments, the sin() method takes the angle in radians, not degrees.
Grundlefleck
+2  A: 

A few tips for you:

What if you combine these two tips?

Grzegorz Oledzki
+7  A: 

The Sin function expects radians.

I think you should use Math.sin(Math.toRadians(90))

wcm