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

Answer:

w is 25.0 x is 1.0


Practice Program

Our goal is to write a program that computes the following sum:

sum = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6

(This may look like a pointless thing to do, but you will see such sums in calculus and elsewhere, where they are called an harmonic series.) Here is a skeleton of the program:


public class HarmonicTester
{
  public static void main ( String[] args )
  {
    int term=1, lastTerm = 6;
    double sum = 0.0;
    
    while ( term <= lastTerm )
    {
       ; // add the next term to sum
      
       ; // increment term
    }
    
    System.out.println("Sum of 6 terms:" + sum ) ;
  }
}

QUESTION 10:

Fill in the two blanks to complete the program.


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