Perfect Number in Java with Source Code

Perfect Number in Java – a perfect number is one whose sum of factors (except the number itself) is equal to the number.

In other terms, a perfect number is one whose sum of positive divisors (excluding the number itself) equals the number itself.

This article has project files included, just scroll down and click the download button and you can edit the project source code for free.

Example Program:

package perfectnumber_in_java;

import java.util.Scanner;

public class PerfectNumber_in_Java {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        long n, sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number");
        n = sc.nextLong();
        int i = 1;
        while (i <= n / 2) {
            if (n % i == 0) {
                sum += i;
            }
            i++;
        }
        if (sum == n) {
            System.out.println(n + " is a perfect number");
        } else {
            System.out.println(n + " is not a  perfect number");
        }
    }
}

Output:

//Perfect Number in Java: Sample Code Output

Enter a number
4
4 is not a  perfect number

What is the importance of Perfect numbers in the Java program?

The Greeks, particularly Euclid, studied perfect numbers extensively because they were thought to have crucial numerological qualities.

According to Proposition IX, is a perfect number. Euclid’s Elements 36

What is the use of a Program for perfect numbers in Java?

A perfect number is an integer with divisors that add up to itself. For example, the number 6 is ideal because. We now have a formula for calculating perfect numbers.

When q is a, Euclid proved that the formula yields an even perfect integer.

About the Project

The sum of their “proper” divisors equals “perfect numbers” (positive integers that divide a number evenly, not counting itself). 6 = 3 + 2 + 1, for example, and 28 = 14 + 7 + 4 + 2 + 1.

The Perfect Number in Java using recursion below covers all of the necessary and vital elements that can be used for college projects by first-year, second-year, and final-year IT students.

The project is entirely written in Java and built in the NetBeans code editor.

Project Details and Technology

Project Name:Perfect Number in Java with Source Code
AbstractPerfect Number in Java A perfect number is a positive integer whose sum of its appropriate divisors equals one.

The sum of 1, 2, and 3 equals 6, which is the lowest perfect number.

The numbers 28, 496, and 8,128 are also perfect. The discovery of such numbers is lost in prehistory.
Language/s Used:Java
Java version (Recommended):8
Database:N/A
Type:Desktop Application
Developer:sourcecodehero
Updates:0

To start executing a Perfect Number in Java with Source Code, make sure that you have  NetBeans IDE or any platform code editor installed on your computer.

How to find a perfect number in Java: Follow the steps below

Time needed: 3 minutes

  • Step 1: Download Source Code

    To get started, find the downloaded source code file below and click to start downloading it.

    Perfect Number in Java

  • Step 2: Extract File

    Navigate to the file’s location when you’ve finished downloading it and right-click it to extract it.

    Perfect Number in Java extract

  • Step 3: Run the project

    Next, open NetBeans IDE and click open project, and choose your download.

    Perfect Number in Java open projects

  • Step 4: Run the project.

    Next, right-click the project folder and click run.

Download the Source Code below

Summary

For those Web developers interested in learning more about web apps, this system is a fully functional project.

Inquiries

If you have any questions or comments on the project, please leave a comment below.

Leave a Comment