I'm still a beginner in Java programming, and I'm using Eclipse Neon. How can I make it like that without writing the code again and again? And at the end, I want to print the final number on the screen.

Here's what I did so far:

``public class othermethod {public static void main(String[] args) {int position = 1;int pos = 0;int[] zahlenlaenge = new int;for (int i = 0; i < zahlenlaenge.length; i++) {zahlenlaenge[pos] = position;position++;pos++;System.out.println(pos);}}}``

How it should actually work: OK, after evaluating what you're asking, I think your confusion lies in what you're doing with tracking your values.

I've taken most of your code and redone it with doubles, and renamed your array to foo for my typing purposes. I'm not sure what you're tracking, but this provides the discerning of what is sum, what is denominator, and if needed, any other values you can pretty quickly figure out where they come from.

``````    double[] foo = new double; //store the sum at any point in array
double sum = 1d; //first value
double denominator = 1d; //first denominator
for (int i = 0; i < foo.length; i++) {
foo[i] = sum; //set the sum to i (1, 2, 2.5, ...)
System.out.println(i + ":" foo[i]);
denominator *= (i + 1); //calculate the next factorial, (1, 2, 3)
sum += 1d / denominator; //calculate the sum (2, 2.5, ...)
}
``````

You'll notice that this quickly normalizes as the `1d / denominator` becomes super-tiny and is basically ignored for calculations.

Top