Advertisement
Guest User

l33t hax 2

a guest
Dec 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.awt.*;
  2. import hsa.Console;
  3.  
  4. public class SumDivisors
  5. {
  6.     static Console c;
  7.    
  8.     public static void main (String[] args)
  9.     {
  10.         c = new Console ();
  11.         c.println("Enter a number.");
  12.         int number = c.readInt();
  13.         c.println("The sum of the divisors is " + sumDiv(number) + ".");
  14.        
  15.     }
  16.    
  17.     static int sumDiv(int n)
  18.     {
  19.         int sum = 0;
  20.         for (int i = 1; i < n; i++)
  21.         {
  22.             if (n % i == 0)
  23.             {
  24.                 sum = sum + i;
  25.             }
  26.         }
  27.         return sum;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement