UVA – 382 – Perfection

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i = 0, sum = 0, N = -1;
        ArrayList<Integer> ns = new ArrayList<Integer>(105);
        while ((N = in.nextInt()) != 0) {
            ns.add(N);
        }
        System.out.printf("PERFECTION OUTPUT\n");
 for (int n : ns) {
            N = n;
            for (sum = 0, i = 1; i < N; i++)
                sum += (N % i == 0) ? i : 0;

            System.out.printf("%5d %s\n", N, (sum < N ?
                              "DEFICIENT" : (sum > N ?
                              "ABUNDANT" : "PERFECT")));
        }
        System.out.printf("END OF OUTPUT\n");
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: