0

//Here is my method that I have created.

//I want my radius1 to equal "7.07" but once I use the method it gives me zero

public double getCircumscribedCircleRadius()
   {
       radius1 = 1 / 2 * 10 * 1 / Math.sin( Math.PI / 4);
       return radius1;
   }
Zach
  • 11

1 Answers1

1

You need to cast you result in double :

 double radius1 = (double) 1 / 2 * 10 * 1 / Math.sin( Math.PI / 4);

output : 7.0710678118654755

Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85
  • Actually what you are doing is casting the first `1` to double and thus starting the computation in double instead of integer arithmetic where `1/2` results in `0`. You could equally replace `(double) 1 / 2` with `0.5` or `(double) 1` with `1.0`. – Lutz Lehmann Mar 01 '17 at 10:39
  • Thank you! I didn't realize that fraction was the problem until you put a (double) in front of the expression to have it get the correct result. Thank you for explaining =) – Zach Mar 02 '17 at 14:19