hawzze

perfect numbers

Apr 17th, 2021
471
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package uni.fmi.bacherlos;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         int n;
  11.         int possibleFactor;
  12.         int factorSum = 0;
  13.  
  14.  
  15.  
  16.         for (n = 2; n < 10000; n++) {
  17.             factorSum = 0;
  18.             for (possibleFactor = 1; possibleFactor <= n / 2; possibleFactor++) {
  19.                 if (n % possibleFactor == 0) {
  20.                     factorSum = possibleFactor + factorSum;
  21.                 }
  22.             }
  23.  
  24.             if (factorSum == n) {
  25.                 System.out.println("" + n + " is a perfect number.");
  26.             }
  27.         }
  28.     }
  29.         }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×