0

I've been struggling with Math.asin() for a while.

System.out.println(Math.toDegrees(Math.asin(1 / 2)));

This very simple line of code pretty much sums up my desperation: The result should be 30°, however, I only get 0.0 as a result. Its not just these numbers, no matter which numbers I use, the result is 0.0. My question is, is this a known bug of Java, or am I missing something?

Bonus Information: I need asin() to calculate the angle between the centerpoints of two objects in my game.

Solo
  • 57
  • 1
  • 11

1 Answers1

0

You’re doing integer division, please add a decimal point in the end of each number like this:

System.out.println(Math.toDegrees(Math.asin(1.0/2.0)))
Azam M
  • 93
  • 1
  • 9
MZ97
  • 142
  • 1
  • 14