4.1 Solutions

  1. 0
  2. No maximum
  3.  
    10 0
    9 2
    8 4
    7 6
  4.  
    void setup()
    {
      int input = getInt("Enter a positive integer");
      int powerOfTwo = 0;
      while(pow(2, powerOfTwo) < input)
        powerOfTwo++;
      println("The smallest power of two greater than or"
              + " equal to " + input + " is 2^" + powerOfTwo);
      exit();
    }
     
  5.  
    void setup()
    {
      int input = getInt("Enter an integer - zero to stop");
      int previousInput = 0;
      int consecutiveCounter = 0;
      while(input != 0)
      {
        if (previousInput == input)
          consecutiveCounter++;
        previousInput = input;
        input = getInt("Enter an integer - zero to stop");
      }
      println("There were " + consecutiveCounter + " equal consecutive values.");
      exit();
    }