Program 5.11: Count the Wheat with Doubles


class CountWheat {

  public static void main (String args[]) {
  
    int i;
    double j, k;
  
    j = 1.0;
    k = 0.0;
  
    for (i=1; i <= 64; i++) {
      k += j;
      System.out.print(k + "\t  ");
      if (i%4 == 0) System.out.println();
      j *= 2.0;
    } 
    System.out.println("All done!");

  }

}

Copyright 1996, 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
This Chapter
Examples
Home