The completed program is given below.
Here is the complete program:
import java.util.Scanner ; class HarmonicSeries { double value( int limit ) { int term=1 ; double sum = 0.0; while ( term <= limit ) { sum += 1.0/term; // add the next term to sum term++ ; // increment term } return sum; } } class HarmonicTester { public static void main ( String[] args ) { Scanner scan = new Scanner(System.in); System.out.print("How many Terms? "); int limit = scan.nextInt(); HarmonicSeries series = new HarmonicSeries(); System.out.println("Sum of " + limit + " terms:" + series.value( limit ) ); } }
With my 750 MHz AMD Athlon
computer it takes
22
seconds to run the program with the limit set at