for loop help

I don't want the answer, just some direction.

Consider the sum 1/2 + 1/4 + 1/8 + ? The first term of this sum is 1/2 = .5. The second term is 1/2 + 1/4 = .75. The third term is 1/2 + 1/4 + 1/8 = .875. Create a program that repeatedly prompts the user for a positive integer, n. Then have the program calculate the nth term of the above sum as a decimal and display it to the user. For example, if the user enters 4, then your program must compute 1/2 + 1/4 + 1/8 + 1/16 = .9375. If the user enters 0, then exit from the program.

I know I need to use a for loop, but I am a little confused

[608 byte] By [kalugaa] at [2007-11-26 18:27:41]
# 1
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
zadoka at 2007-7-9 6:01:50 > top of Java-index,Java Essentials,New To Java...
# 2

Consider this:

//calculates the sum of 1-n

int n = 5;

int sum = 0;

for(int i=1; i<=n; i++)

{

sum += i;

}

System.out.println(sum);

Instead of adding one each time, you're halving the number.

CaptainMorgan08a at 2007-7-9 6:01:50 > top of Java-index,Java Essentials,New To Java...
# 3
Don't you see that each time thru the loop, you multiply a denominator by 2, and add 1 / (denominator) to the cumulative result?
warnerjaa at 2007-7-9 6:01:50 > top of Java-index,Java Essentials,New To Java...