Shavit

Ex. Bank #26

Dec 7th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. // Shavit Borisov
  2. // HW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class PerfectNumber {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int num, dividersSum = 0;
  14.        
  15.         System.out.printf("Enter a number: ");
  16.         num = in.nextInt();
  17.        
  18.         for(int i = 1; i < num; i++)
  19.             if((num % i) == 0)
  20.                 dividersSum += i;
  21.            
  22.         if(dividersSum == num)
  23.             System.out.printf("%d is a perfect number", num);
  24.        
  25.         else
  26.             System.out.printf("%d is just a regular number", num);
  27.        
  28.         in.close();
  29.     }
  30. }
Add Comment
Please, Sign In to add comment