// This is a particularly elegant solution. Your solution doesn't have to be this // compact. import java.util.*; /** * Assignment 1: Self Divisor * * * @author Student From COMP401 *
* TA: Catalin Constantin. *
* Recitation section: Comp401.602 *
* Date: February 7, 2008
*
* Description:
* This program generates an array of self divisors which are then
* displayed on the screen. The program asks for two input parameters:
* the base number to start from, and a count of how many self divisors
* should the array have. A self divisor is a number divisible by all
* of its digits.
*
*
* Pledged: I have neither given nor received unauthorized aid on
* this program.
*
*
* Input: The base and the count.
*
* Output: Greeting and list of self divisors.
*
* Errors checked for: none
*
* Restrictions: Both the starting integer (base) and the number of self divisors
* (count) need to be greater than 0.
*
*/
public class SelfDivisors
{
/**
* The main method. It loops asking for input until a 0 or negative
* base is entered.
* @param args standard
*/
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
/* greeting and info */
System.out.println("This program will generate a list of self divisors.");
/* getting input parameters from the user */
System.out.print("\n\nHow many self divisors: ");
int count = kb.nextInt();
System.out.print("Enter starting number (0 finish): ");
int base = kb.nextInt();
/* loop until 0 or negative */
while(base>0)
{
/* obtain the list of self divisors */
int[] sdArray = selfDivArray(base, count);
/* print out the self divisors */
System.out.println("\n" + count + " self divisors from "+ base);
for(int i=0; i