SECOND EXAM will bw on Dec 1, 2003 .
1. Write a program that reads a number and then prints the sum of its divisors. The divisor of a number is one that when the number is divided by it, the remainder is zero. Thus if the number read is 16, the program would print the sum of 1 + 2 + 4 + 8, or 15.

2. Write a program that reads characters until it encounters a period. It then prints the character read before the period. Thus if the input is {\tt asd5f.}, the program prints

3. What does the following program produce?
public class Prog3
{
  public void plot(int j)
  {
     for(int i = 0; i < j; i++)
     {
        for(int k =0; k <= j; k++)
           System.out.print(' ');
       System.out.println(j);
     }
        
  public static void main(String[] asd)
  {
    int digit;
    for(char number = '0'; number <= '3'; number++)
    {
            digit = number - '0';
            plot(digit);
    }
  }
}


4. Evaluate the following (you may use the table on the board):
(a) (7 >= 3) || ! 9 == 8)	    (b)  !(4 >= 5) &&  !(3 <  3)

(c) !((5 == 9) || !(3 > 2))    (d) (6 <= 8) && (3 < 5) && (3 = 3)

5. What does the following code produce?
public class WhatDoIDo
{
      public static void main (String [] args)
      {
           print(8);
           print(3);
      }

      public static void print(int number)
      {
           int index, uScores, numToShow;
           numToShow = formula(number);
           for(index = 1; index <= number; index++)
           {
                 for(uScores = 1; uScores <= index; uScores ++)
                      System.out.print(``_'');
                 System.out.println(numToShow);
           }
      }

      public static int formula(int value)
      {
           return (value % 3) + 1;
      }
}


6. Write a method that takes three integers as parameters and returns the largest of the three.