go to previous page   go to home page   go to next page hear noise highlighting

Answer:

The completed program is given below.


Complete Program

import java.util.Scanner ;

public class HarmonicTester
{
  public static void main ( String[] args ) 
  {
    Scanner scan = new Scanner(System.in);
    System.out.print("How many Terms? ");
    int limit = scan.nextInt();
 
    int term=1 ;
    double sum = 0.0;
    
    while ( term <=  limit )
    {
      sum += 1.0/term;           // add the next term to sum
      term++ ;                   // increment term
    }
 
    System.out.println("Sum of " + limit + " terms:" +  sum );
  }
}

QUESTION 13:

With my 750 MHz AMD Athlon computer it takes 22 seconds to run the program with the limit set at 1,000,000,000.

With my more recent 3.3 GHz Ryzen computer this takes 4 seconds.

Is your computer slower or faster than mine?


go to previous page   go to home page   go to next page