FAQs
Search
Recent Topics
Flagged Topics
Hot Topics
Best Topics
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Java JSRs
Mobile
Certification
Databases
Caching
Books
Engineering
Languages
Frameworks
Products
This Site
Careers
Other
all forums
Forum:
Beginning Java
Help! Math question.
Joe Budden
Greenhorn
Posts: 2
posted 10 years ago
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: 2409
posted 10 years ago
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.
Post Reply
Bookmark Topic
Watch Topic
New Topic
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