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?

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)

Edited 3 Years Ago by JamesCherrill

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

This question has already been answered. Start a new discussion instead.