The completed program is given below
Here is the completed program:
class HarmonicSeries
{
double value()
{
int term=1, lastTerm = 6;
double sum = 0.0;
while ( term <= lastTerm )
{
sum += 1.0/term; // add the next term to sum
term++ ; // increment term
}
return sum;
}
}
class HarmonicTester
{
public static void main ( String[] args )
{
HarmonicSeries series = new HarmonicSeries();
System.out.println("Sum of 6 terms:" + series.value() );
}
}
You might wish to copy this program to your editor and run it. If you do, you will see something like:
C:\users>java HarmonicTester Sum of 6 terms:2.4499999999999997