Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import hsa.Console;
- public class SumDivisors
- {
- static Console c;
- public static void main (String[] args)
- {
- c = new Console ();
- c.println("Enter a number.");
- int number = c.readInt();
- c.println("The sum of the divisors is " + sumDiv(number) + ".");
- }
- static int sumDiv(int n)
- {
- int sum = 0;
- for (int i = 1; i < n; i++)
- {
- if (n % i == 0)
- {
- sum = sum + i;
- }
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement