Results 1 to 4 of 4
Thread: Need help with sin in java
- 02-16-2012, 10:53 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 9
- Rep Power
- 0
Need help with sin in java
I'm working sin in java but I have a issue.
How can I get rid of the unnecessary zero's in my program.
This is how it is supposed to end up.Here is how mine ends up.Java Code:Angle Sin -90.0 -1.0 -75.0 -0.965926 -60.0 -0.866025 -45.0 -0.707107 -30.0 -0.5 -15.0 -0.258819 0.0 0.0 15.0 0.258819 30.0 0.5 45.0 0.707107 60.0 0.866025 75.0 0.965926 90.0 1.0
Here is my code.Java Code:Angle Sin -90.0 -1.000000 -75.0 -0.965926 -60.0 -0.866025 -45.0 -0.707107 -30.0 -0.500000 -15.0 -0.258819 0.0 0.000000 15.0 0.258819 30.0 0.500000 45.0 0.707107 60.0 0.866025 75.0 0.965926 90.0 1.000000
Java Code:import java.text.*; public class prog232 { public static void main(String[] args){ double a,b; DecimalFormat numform = new DecimalFormat("0.000000"); a = -105.0; while (a <= 75){ a = a + 15; b = Math.sin(Math.toRadians(a)); System.out.println("" + a + " " + numform.format(b)); } } }
-
Re: Need help with sin in java
Please Google and read up on the limitations of using digital hardware to represent floating point numbers and you'll see why your request is not trivial. Also, personally, I like your out better than the first output.
- 02-16-2012, 11:52 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 9
- Rep Power
- 0
Re: Need help with sin in java
Nevermind. It was actually very trivial and I figured it out.
- 02-17-2012, 12:02 AM #4


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks