public class PolarCoordinates {

    public static void main(String[] args){

        int r=10;
        double x=0,y=0,theta=30;
     x=r*Math.cos(theta);
    y=r*Math.sin(theta);

        System.out.println("The value of x is :" +x);
        System.out.println("The value of y is :" +y);



}
}

help please?
it gives me wrong answer.
10cos(30) should equal to 8.7, but it gives me 11.7 ans.
10sin(30) should equal to 5, and it gives me 2.63 ans.
whats wrong with my code?

sin. cos etc use angles in radians, your data (30) looks like degrees.

30° equals pi/6 rad

oh yes, its a degrees.
what's wrong with my formula?

To convert yout theta value from degrees to radians use: theta = (theta * 3.141592)/360;

what's wrong with my formula?

sin. cos etc use angles in radians (Google it), you have supplied an angle in degrees

Pi radians is 180 degrees, so ddanbe' formula should be theta = theta * Math.PI / 180;
(sorry ddanbe)

Oops!!! Thanks for correcting me JamesCherrill, 2*pi rad = 360° and not pi rad = 360° of course!

ohh, ok! thanks! i got it now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.