Computer Science 261

Assignment # 2

Due: Monday, Sept. 10

Purpose:


A number (positive integer) is perfect if the sum of its divisors less than the number is equal to the number. For example, 6 = 1 + 2 + 3 is a perfect number. If the sum of the divisors is less than the number, we say the number is deficient. If the sum of the divisors is greater than the number, it is abundant. If the only divisor of the number is 1 (and the number itself, of course), then the number is prime.

Write a program which takes an integer as its first argument and prints out a message saying whether the number is perfect, abundant, deficient, or prime. Be efficient in your use of loops and if-then-else statements.

Call this program perfect.java and place it in your handins folder.

Recall the following code from today's example:

 int k;

 System.out.println("Number of arguments is " + args.length);
 for (int i = 0; i < args.length; ++i)
  {
     System.out.println("Argument " + (i+1) + " " + args[i]);
  }
  k = Integer.valueOf(args[0]).intValue();

  System.out.println("Numeric value of first argument is " + k);