- #1
OK here is my source code for a small Java program I wrote to approximate the number e:
What's wrong with this code? When I run this program and enter 100000 for number_of_digits, I get a result of e = 4.999950002E9. What's up with this?
P.S.: This is the latest Java SDK (1.6) I am compiling this program in.
Code:
import java.util.Scanner;
public class E
{
public static void main (String[] args)
{
double e = 0.00, current_e = 0.00;
int x, number_of_digits;
Scanner scan = new Scanner (System.in);
System.out.println("How many digits?");
number_of_digits = scan.nextInt();
for (x=1; x<number_of_digits; x++)
{
current_e = (1 + (1/x)) ^ x;
e += current_e;
}
System.out.println("e = " + e);
}
}
What's wrong with this code? When I run this program and enter 100000 for number_of_digits, I get a result of e = 4.999950002E9. What's up with this?
P.S.: This is the latest Java SDK (1.6) I am compiling this program in.