Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with programming exercise

807603Nov 20 2007 — edited Nov 20 2007
This is my assignment:

Exercise 36 � Computation
Write a program that computes the following sum:
sum = 1.0/1 + 1.0/2 + 1.0/3 + 1.0/4 + 1.0/5 + .... + 1.0/N

N will be an integer limit that the user enters.

Enter N
4

Sum is: 2.08333333333

And this is what I have so far:

import learning.*;
class Computation
{
public static void main(String[] args)
{
int N;
double Sum;

System.out.println("Enter N");
N = LearningIO.readInt();

Sum = 1.0/N;

for ( N= 1; <=N ; Sum++)
{
System.out.println(Sum);
}
}
}

I don't know what to use for the termination process. Any help will be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2007
Added on Nov 20 2007
4 comments
328 views