A friendly place for programming greenhorns!
Big Moose Saloon
Search

Java FAQ

Recent Topics

Flagged Topics

Hot Topics

Zero Replies
Register / Login
Win a copy of
Badass: Making Users Awesome
this week in the
Game Development
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Help! Math question.
Joe Budden
Greenhorn
Joined: Mar 22, 2006
Posts: 2
posted
Mar 22, 2006 23:46:00
0
I have a question, given the following code:
public class NormalDist { public static void main(String[] args) { System.out.println(((float)1/(float)(Math.sqrt(2*Math.PI))) * (float)(Math.exp((1/2) * (.01 * .01)))); System.out.println(((float)1/(float)(Math.sqrt(2*Math.PI))) * (float)(Math.exp((1/2) * (1.5 * 1.5)))); } }
Why is the output the same of:
0.3989423
0.3989423
All help appreciated. Thank you.
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2367
posted
Mar 23, 2006 00:10:00
0
Math.exp((1/2) * (.01 * .01))
Remember that when you divide an int by an int, the result is an int. The operations in parentheses are done seperately.
Since 1/2 is 0, the result will be e^0 = 1 regardless of what you multiply 1/2 by.
subject: Help! Math question.
Similar Threads
calculator program help please
Digital Signal Processing (DSP, FFT, Spectrum)
Math.sqrt()
Problem with my application never exiting the main
Dan's exam class SRC108
All times are in JavaRanch time: GMT6 in summer, GMT7 in winter