wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Division problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Division problem" Watch "Division problem" New topic
Author

Division problem

Tomm Schuman
Greenhorn

Joined: Mar 04, 2005
Posts: 11
Why does the code below print 1.0 if heading is 50? The real answer is 1.8
Rad is a double and heading an int.

I'm trying to convert degrees to rad, tell me if there's a better way to do it than the one i use. Thx in advance

Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
If heading is an int, then the result of 180/50/2 will be truncated.



What about Math.toDegrees() and Math.toRadians()

Looking at the source of Math class :

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
use the toRadians(double degrees) method...

for example



Regards
Prashanth Lingala


Have A Nice Day !!!
Tomm Schuman
Greenhorn

Joined: Mar 04, 2005
Posts: 11
O there was already a method which does that

I have had sin,cos,tan in school but I don't really know how to use them in programming. Could someone give me an example about how you calculate the X in the triangle below.

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Using a little bit of trigonometry, you can set up an equation:

Solving this for x, you get

You can convert this almost directly into Java using the Math class:

The Math class also provides methods for cosine, tangent, and other nifty mathematical functions. See the link provided above for the Javadocs for this class.

HTH

Layne
[ March 10, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
May be you like this Commons-Math Library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Division problem