Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Help! Math question.
Joe Budden
Greenhorn
Posts: 2
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 2412
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
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
More...