4.3 Solutions

    1.  
      *******
    2.  
      5 seconds
      4 seconds
      3 seconds
      2 seconds
      1 seconds
    3.  
      Give me a P
      Give me a Q
      Give me a R
      Give me a S
    4.  
      2
      4
      16
    1.  
      for (x = 6; x >= 0; x--)
         println("x = " + x + ", 2x + 5 = " + (2*x + 5)); 
    2.  
      for (x = 0; x <= 30; x += 3)
         println("x = " + x + ", 2x + 5 = " + (2*x + 5)); 
    3.  
      for (x = -15; x <= 15; x += 5)
         println("x = " + x + ", 2x + 5 = " + (2*x + 5)); 
    4.  
      for (x = 1; x <= 1024; x *= 2)
         println("x = " + x + ", 2x + 5 = " + (2*x + 5)); 
    1.  
      float sum = 0;
      for (int i = 1; i <= 1000; i++)
        sum += 1.0 / i; 
    2.  
      float sum = 0;
      for (int i = 100; i <= 5000; i += 100)
        sum += sqrt(i); 
    3.  
      long product = 1;
      for (int i = 1; i <= 20; i++)
        product *= i; 

  1.  
    void setup()
    {
       int input = getInt("Please enter an integer.");
       for (int i = 1; i <= input; i++)
          println(input + " x " + i + " = " + (i * input));
    }
    1.  
      void setup()
      {
         final int UPPER_BOUND = 40;
         println("Number Square Square Root Reciprocal");
         for (int i = 1; i <= UPPER_BOUND; i++)
         {
            print(i + "  ");
            print(i*i + "  ");
            print(nf(sqrt(i),1, 5) + "  ");
            println(nf(1/(float)i,1, 5));
         }
      } 
    2. Simply add the following at the end of the for loop
      if (i % 5 == 0)
        println();