conversion from radian to degree

i am writing code of java swing scientific calculator .... for sin, cos and tan functions i am using math.sin, math.cos etc .... problem is that it is giving answer in radian ..... i need answer in degree ..... can any one help me to solve my this problem
[262 byte] By [Sara_Khana] at [2007-11-26 15:04:45]
# 1
pi radians == 180 degrees (half way round a circle). So:x radians == (180/pi)*x degrees and y degrees == (pi/180)*y radians.kind regards,Jos
JosAHa at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 2
i already used this method but didn't get right answer result = Math.sin(getNumberInDisplay());result = result*(3.14)/180;displayResult(result);this is code ............ what should i do?
Sara_Khana at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 3
3.14 is accurate for pi, but it's not very precise.Try using Math.PI instead.%
duffymoa at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 4

> i already used this method but didn't get right answer

>

> result = Math.sin(getNumberInDisplay());

> result = result*(3.14)/180;

> displayResult(result);

>

> this is code ............ what should i do?

Read the API docs for the Math class again: it has to useful methods:

toDegrees and toRadians. They go like this:double degrees= Math.toDegrees(radians);

double radians= Math.toRadians(degrees);

kind regards,

Jos

JosAHa at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 5
i also used these methods but didn't get right asnwer :(
Sara_Khana at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 6
> i also used these methods but didn't get right asnwer :(Care to elaborate a bit more? My psychic batteries are in 'weekend mode'so I can't read your mind; what exactly is a 'right answer'?kind regards,Jos
JosAHa at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 7

>> i also used these methods but didn't get right asnwer :(

well its not us or the math library. there must be something wrong

with your code other then the conversion.

public class DegreesToRadians{

public static void main(String[] args) {

double degrees = 180;

System.out.println("Degrees: " + degrees);

double radians = Math.toRadians(degrees);

System.out.println("Degrees: " + radians);

}

}

TuringPesta at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...
# 8

> i already used this method but didn't get right

> answer

>

> result = Math.sin(getNumberInDisplay());

> result = result*(3.14)/180;

> displayResult(result);

>

> this is code ............ what should i do?

Learn some mathematics to start with.

The result of the sine function is not an angle, it's the sine of the angle.

You only apply that transformation from radians to degrees and back to the angle, not the sine of the angle.

If you want to get an angle out of a trig function, you usually have to apply the inverse.

What does that "getNumberinDisplay()" method return? (Bad name - most unclear.) If it's an angle, that's the thing that needs to be transformed. Math trig functions usually deal with radians.

I'm betting this is the right thing:

double angle = Math.toRadians(getNumberInDisplay());

doube result = Math.sine(angle);

System.out.println("angle (radians): " + angle + " sin(angle): " + result);

%

duffymoa at 2007-7-8 8:54:29 > top of Java-index,Java Essentials,New To Java...