1

I try to show the value of sin 30 in java (eclipse). But it's not a real value, My code :

public class sin30 {
public static void main(String[] args){

    System.out.println("Sin 30 = "+Math.sin(30));

}}

and show : Showing

should sin 30 is 0.5. what's wrong with my code?

  • 1
    well you probably won't get exactly 0.5 even when using radians due to floating point arithmetic – Reimeus Apr 08 '16 at 23:36

2 Answers2

9

Math.sin expects a value in radians

System.out.println("Sin 30 = "+ Math.sin(Math.toRadians(30)));
Reimeus
  • 158,255
  • 15
  • 216
  • 276
2

Before should transform it in Radiant like this:

  double radians = Math.toRadians(30);
  System.out.println("Sin 30 = "+Math.sin(radians));
Abdelhak
  • 8,299
  • 4
  • 22
  • 36