{"id":62567,"date":"2022-08-23T07:28:36","date_gmt":"2022-08-23T07:28:36","guid":{"rendered":"https:\/\/itsourcecode.com\/?p=62567"},"modified":"2022-08-23T07:56:48","modified_gmt":"2022-08-23T07:56:48","slug":"perfect-number-in-java-with-program-examples","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/","title":{"rendered":"Perfect Number In Java With Program Examples"},"content":{"rendered":"\n<p>In this article, we will learn about <strong><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">perfect number in Java<\/mark><\/strong>. This article also has the best program examples to check whether the number is perfect or not.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"1024\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-819x1024.jpg\" alt=\"Perfect Number In Java\" class=\"wp-image-76492\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-819x1024.jpg 819w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-240x300.jpg 240w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-768x960.jpg 768w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-1229x1536.jpg 1229w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1-1638x2048.jpg 1638w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/altumcode-P2SkP_PXhlU-unsplash-1.jpg 1920w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/a><figcaption>Perfect Number In Java<\/figcaption><\/figure>\n\n\n\n<p>Any number may qualify as a <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>Java Perfect Number<\/strong><\/mark> if the total of its positive factors, excluding the number itself, equals the value of the number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-perfect-number-in-java\"><strong>What is a perfect number in Java<\/strong><\/h2>\n\n\n\n<p>In Java, a <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>perfect number<\/strong><\/mark> is one whose factors, minus the number itself, add up to the number itself. In other words, a number is called &#8220;<code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">perfect<\/mark><\/code>&#8221; if the sum of its positive divisors, minus the number itself, equals the number itself. Let&#8217;s use an example to understand it.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<p><code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">28<\/mark><\/code> is a perfect number because it can be divided by <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><code>1<\/code><\/mark>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">2<\/mark><\/code>,<mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><code> 4<\/code><\/mark>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">7<\/mark><\/code>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">14<\/mark><\/code>, and <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">28<\/mark><\/code>, and the total of these numbers is <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">28<\/mark><\/code>. Don&#8217;t forget that we need to leave out the number itself. We didn&#8217;t add 28 because of this.<mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"> <strong>Java perfect numbers<\/strong><\/mark> include <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">6<\/mark><\/code>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">28<\/mark><\/code>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">496<\/mark><\/code>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">8128<\/mark><\/code>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">33550336,<\/mark><\/code> and so on.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-do-you-calculate-a-perfect-number\"><strong>How do you calculate a perfect number?<\/strong><\/h2>\n\n\n\n<p>A number is perfect if the sum of its proper divisors equals the sum itself. To find the correct factors of a <a href=\"https:\/\/itsourcecode.com\/java-tutorial\/number-classes-in-java-with-example-and-best-explanation\/\">number<\/a>, write down all the numbers that divide the number except the number itself. If the total of the factors is 28, then 28 is a perfect number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-7-ways-to-find-the-perfect-number\"><strong>7 Ways to find the perfect number<\/strong><\/h2>\n\n\n\n<p>The following are different ways in a Java program to check if a number is perfect or not.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using method<\/li><li>Using for loop<\/li><li>Using while loop<\/li><li>Using functions<\/li><li>Using recursion<\/li><li>Using array<\/li><li>Using OOPS (Object Oriented Programming)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-method\"><strong>Example program using method<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class usingMethod\n\n{\n\n    \/\/function that checks if the given number is perfect or not  \n\n    static long isPerfect(long num)\n\n    {\n\n        \/\/variable stores the sum    \n\n        long sum = 0;\n\n        \/\/executes until the condition becomes false  \n\n        for (int i = 1; i &lt;= num \/ 2; i++)\n\n        {\n\n            if (num % i == 0)\n\n            {\n\n                \/\/calculates the sum of factors  \n\n                sum = sum + i;\n\n            } \/\/end of if  \n\n        } \/\/end of for  \n\n        \/\/returns the sum of factors  \n\n        return sum;\n\n    } \/\/end of method  \n\n    public static void main(String args&#91;])\n\n    {\n\n        long number, s;\n\n        Scanner sc = new Scanner(System.in);\n\n        System.out.print(\"Enter the number: \");\n\n        \/\/reads a number from the user  \n\n        number = sc.nextLong();\n\n        \/\/calling the function  \n\n        s = isPerfect(number);\n\n        \/\/compares sum with the number  \n\n        if (s == number)\n\n            System.out.println(number + \" is a perfect number\");\n\n        else\n\n            System.out.println(number + \" is not a perfect number\");\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the number: 26 is not a perfect number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-for-loop\"><strong>Example program using for loop<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Write Perfect Number program in Java using For Loop *\/\n\nimport java.util.Scanner;\n\n\n\npublic class PerfectNumberUsingFor {\n\n    private static Scanner sc;\n\n\n\n    public static void main(String&#91;] args) {\n\n        int i, Number, Sum = 0;\n\n        sc = new Scanner(System.in);\n\n        System.out.println(\"\\n Please Enter any Number: \");\n\n        Number = sc.nextInt();\n\n\n\n        for (i = 1; i &lt; Number; i++) {\n\n            if (Number % i == 0) {\n\n                Sum = Sum + i;\n\n            }\n\n        }\n\n        if (Sum == Number) {\n\n            System.out.format(\"\\n% d is a Perfect Number\", Number);\n\n        } else {\n\n            System.out.format(\"\\n% d is NOT a Perfect Number\", Number);\n\n        }\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> 28 is a Perfect Number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-while-loop\"><strong>Example program using while loop<\/strong><\/h2>\n\n\n\n<p>This example program using a <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>while loop<\/strong><\/mark> lets the user enter any number. Using this number, the while <a href=\"https:\/\/itsourcecode.com\/java-tutorial\/loops-in-java-best-and-complete-guide-for-beginners\/\">loop<\/a> will check if the user&#8217;s input is a perfect number or not.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class PerfectNumberUsingWhile {\n\n    private static Scanner sc;\n\n    public static void main(String&#91;] args) {\n\n        int i = 1, Number, Sum = 0;\n\n        sc = new Scanner(System.in);\n\n        System.out.println(\"Please Enter any Number: \");\n\n        Number = sc.nextInt();\n\n\n\n        while (i &lt; Number) {\n\n            if (Number % i == 0) {\n\n                Sum = Sum + i;\n\n            }\n\n            i++;\n\n        }\n\n        if (Sum == Number) {\n\n            System.out.format(\"%d is a Perfect Number\", Number);\n\n        } else {\n\n            System.out.format(\"%d is NOT a Perfect Number\", Number);\n\n        }\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>28 is a Perfect Number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-functions\"><strong>Example program using functions<\/strong><\/h2>\n\n\n\n<p>The user can enter any integer value into this program, and we&#8217;ll send that value to the<a href=\"https:\/\/itsourcecode.com\/java-tutorial\/methods-in-java-types-class-main-parameters-void-and-examples\/\"> method<\/a> we created.<\/p>\n\n\n\n<p>This program will use the For Loop in this user-defined function to check if the user input is a perfect number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class PerfectNumberUsingMethod {\n\n    private static Scanner sc;\n\n    public static void main(String&#91;] args) {\n\n        int Number;\n\n        sc = new Scanner(System.in);\n\n        System.out.println(\"Please Enter any Number: \");\n\n        Number = sc.nextInt();\n\n        PerfectNumber(Number);\n\n    }\n\n    public static void PerfectNumber(int Number) {\n\n        int i, Sum = 0;\n\n        for (i = 1; i &lt; Number; i++) {\n\n            if (Number % i == 0) {\n\n                Sum = Sum + i;\n\n            }\n\n        }\n\n        if (Sum == Number) {\n\n            System.out.format(\"%d is a Perfect Number\", Number);\n\n        } else {\n\n            System.out.format(\"%d is NOT a Perfect Number\", Number);\n\n        }\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Please Enter any Number:  496 is a Perfect Number<\/code><\/pre>\n\n\n\n<p>Our function is designated as void in this instance and has no return value. We therefore refer to it as a function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PerfectNumber (Number);<\/code><\/pre>\n\n\n\n<p>In the main() program, the Javac compiler will instantly jump to the following method when it hits the PerfectNumber(Number) line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void PerfectNumber (int Number) {<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-oops-object-oriented-programming\">Example program using OOPS (Object-Oriented Programming)<\/h2>\n\n\n\n<p><strong><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">Object-Oriented Programming<\/mark><\/strong> is used to divide the code in this program. First, we&#8217;ll make a class with a method for finding the sum of factors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package FrequentPrograms;\n\npublic class PerfectNumber {\n\n    int i, Sum = 0;\n\n    public int FindPerfectNumber(int Number) {\n\n        for (i = 1; i &lt; Number; i++) {\n\n            if (Number % i == 0) {\n\n                Sum = Sum + i;\n\n            }\n\n        }\n\n        return Sum;\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>We will make an instance of the above class and call the methods within the main program.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package FrequentPrograms;\n\nimport java.util.Scanner;\n\npublic class PerfectNumberUsingClass {\n\n    private static Scanner sc;\n\n    public static void main(String&#91;] args) {\n\n        int Number, Sum = 0;\n\n        sc = new Scanner(System.in);\n\n        System.out.println(\"Please Enter any Number: \");\n\n        Number = sc.nextInt();\n\n        PerfectNumber pn = new PerfectNumber();\n\n        Sum = pn.FindPerfectNumber(Number);\n\n        if (Sum == Number) {\n\n            System.out.format(\"%d is a Perfect Number\", Number);\n\n        } else {\n\n            System.out.format(\"%d is NOT a Perfect Number\", Number);\n\n        }\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Please Enter any Number:  496 is a Perfect Number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-recursion\"><strong>Example program using recursion<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main\n\n{\n\n    static int number = 28;\n\n    static int sum = 0;\n\n    static int div = 1;\n\n    static int findPerfect(int number, int div) {\n\n        {\n\n            if (div &lt;= number \/ 2)\n\n            {\n\n                if (number % div == 0)\n\n                {\n\n                    sum += div;\n\n                }\n\n                div++;\n\n                findPerfect(number, div);\n\n            }\n\n            return sum;\n\n        }\n\n    }\n\n    public static void main(String args&#91;])\n\n    {\n\n        int result = findPerfect(number, div);\n\n        if (result == number)\n\n            System.out.println(\"It is Perfect Number\");\n\n        else System.out.println(\"It is not Perfect Number\");\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>It is Perfect Number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-using-array\"><strong>Example program using array<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class PIES {\n\n  \/\/ Function to return the sum of\n\n  \/\/ all the proper factors of n\n\n  static int sumOfFactors(int n)\n\n  {\n\n    int sum = 0;\n\n    for (int f = 1; f &lt;= n \/ 2; f++) {\n\n      \/\/ f is the factor of n\n\n      if (n % f == 0) {\n\n        sum += f;\n\n      }\n\n    }\n\n    return sum;\n\n  } \n\n  \/\/ Function to return the required sum\n\n  static int getSum(int&#91;] arr, int n)\n\n  {\n\n    \/\/ To store the sum\n\n    int sum = 0;\n\n    for (int i = 0; i &lt; n; i++) { \n\n      \/\/ If current element is non-zero and equal\n\n      \/\/ to the sum of proper factors of itself\n\n      if (arr&#91;i] &gt; 0 &amp;&amp; arr&#91;i] == sumOfFactors(arr&#91;i])) {\n\n        sum += arr&#91;i];\n\n      }\n\n    }\n\n    return sum;\n\n  }\n\n \n\n  \/\/ Driver code\n\n  public static void main(String&#91;] args)\n\n  {\n\n    int&#91;] arr = { 18, 10, 6, 6, 4 };\n\n    int n = arr.length;\n\n    System.out.print(getSum(arr, n));\n\n  }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>12<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-to-find-the-perfect-number-between-1-and-1000\"><strong>Example program to find the perfect number between 1 and 1000<\/strong><\/h2>\n\n\n\n<p>The user can put in the minimum and maximum values in this program. This Java program finds the perfect number between the minimum and maximum values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Java Program to Find Perfect Number between 1 to 1000\n\nimport java.util.Scanner;\n\npublic class PerfectNumbersbetweenMin {\n\n    private static Scanner sc;\n\n    public static void main(String&#91;] args) {\n\n        int i, Number, Minimum, Maximum, Sum = 0;\n\n        sc = new Scanner(System.in);\n\n        System.out.println(\"Please Enter the Minimum Value: \");\n\n        Minimum = sc.nextInt();\n\n        System.out.println(\"Please Enter the Maximum Value: \");\n\n        Maximum = sc.nextInt();\n\n\n\n        \/\/sum n system.out.println\t\t\n\n        for (Number = Minimum; Number &lt;= Maximum; Number++) {\n\n            for (i = 1, Sum = 0; i &lt; Number; i++) {\n\n                if (Number % i == 0) {\n\n                    Sum = Sum + i;\n\n                }\n\n            }\n\n            if (Sum == Number) {\n\n                System.out.format(\"%d \\t\", Number);\n\n            }\n\n        }\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Please Enter the Minimum Value: 1\n\nPlease Enter the Maximum Value: 20000\n\n6 \t28 \t496 \t8128 \t\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-program-for-perfect-number-inside-a-given-range\"><strong>Example program for perfect number inside a given range<\/strong><\/h2>\n\n\n\n<p>The following program locates all the perfect integers that fall within a certain range.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class PerfectNumberExample3 {\n\n    \/\/function checks if the given number is perfect or not  \n\n    static boolean isPerfectNumber(int num) {\n\n        \/\/variable stores the sum of divisors  \n\n        int sum = 1;\n\n        \/\/determines all the divisors of the given number and adds them  \n\n        for (int i = 2; i * i &lt;= num; i++) {\n\n            if (num % i == 0) {\n\n                if (i * i != num)\n\n                    sum = sum + i + num \/ i;\n\n                else\n\n                    \/\/calculates the sum of factors  \n\n                    sum = sum + i;\n\n            } \/\/end of if  \n\n        } \/\/end of for  \n\n        if (sum == num &amp;&amp; num != 1)\n\n            \/\/returns true if both conditions (above) returns true  \n\n            return true;\n\n        \/\/returns false if any condition becomes false  \n\n        return false;\n\n    } \/\/end of function  \n\n    \/\/driver code  \n\n    public static void main(String args&#91;]) {\n\n        System.out.println(\"Perfect Numbers between 2 to 10000 are: \");\n\n        \/\/loop executes until the condition n&lt;10000 becomes false  \n\n        for (int n = 2; n &lt; 10000; n++)\n\n            \/\/calling function  \n\n            if (isPerfectNumber(n))\n\n                \/\/prints all perfect number between given range  \n\n                System.out.println(n + \" is a perfect number\");\n\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Perfect Numbers between 2 to 10000 are: \n\n6 is a perfect number\n\n28 is a perfect number\n\n496 is a perfect number\n\n8128 is a perfect number<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-are-the-perfect-numbers-from-1-to-100\"><strong>What are the perfect numbers from 1 to 100?<\/strong><\/h2>\n\n\n\n<p>There are only two perfect numbers from 1 to 100. These are <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">6<\/mark><\/code> and <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">28<\/mark><\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-is-496-a-perfect-number\"><strong>Why is 496 a perfect number?<\/strong><\/h2>\n\n\n\n<p>In <a href=\"https:\/\/realpython.com\/python-math-module\/#:~:text=For%20straightforward%20mathematical%20calculations%20in,functions%2C%20are%20not%20built%20in.\">mathematics<\/a>, <code><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\">496<\/mark><mark style=\"background-color:var(--base-3)\" class=\"has-inline-color has-base-3-color\"> <\/mark><\/code>is most famous for being a <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>perfect number<\/strong><\/mark>, and it was one of the first numbers for which this was known. As a perfect number, it is equal to the Mersenne prime 31, 25 1, with 24 (25 1) equaling 496.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-are-the-perfect-numbers-from-1-to-10000\"><strong>What are the perfect numbers from 1 to 10000?<\/strong><\/h2>\n\n\n\n<p>Nicomachus noticed around 100 C.E. that <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>perfect numbers<\/strong><\/mark> strike a balance between extremes of excess and deficiency, like when the sum of a number&#8217;s positive divisors, excluding the number, is too big or too small, and falls in the &#8220;right&#8221; order. The only perfect numbers between 1, 10, 100, 1000, and 10000 are <mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>6, 28, 496, and 8128<\/strong><\/mark>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-the-importance-of-perfect-numbers\"><strong>What is the importance of perfect numbers?<\/strong><\/h2>\n\n\n\n<p><mark style=\"background-color:var(--base)\" class=\"has-inline-color has-accent-color\"><strong>Perfect numbers <\/strong><\/mark>provide a solid number theory illustration of the principle of classification in the Fibonacci series.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>I hope this lesson has helped you learn a lot. Check out my previous and latest articles for more life-changing tutorials which could help you a lot.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn about perfect number in Java. This article also has the best program examples to check whether the number is perfect or not. Any number &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Perfect Number In Java With Program Examples\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#more-62567\" aria-label=\"Read more about Perfect Number In Java With Program Examples\">Read more<\/a><\/p>\n","protected":false},"author":2342,"featured_media":62580,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61033],"tags":[95060],"class_list":["post-62567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorial","tag-java-perfect-number","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Perfect Number In Java With Program Examples - 2022 New<\/title>\n<meta name=\"description\" content=\"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Perfect Number In Java With Program Examples\" \/>\n<meta property=\"og:description\" content=\"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-23T07:28:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-23T07:56:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1460\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Glenn Azuelo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Glenn Azuelo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/\"},\"author\":{\"name\":\"Glenn Azuelo\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/a1fb91e119811c0240699578286f83eb\"},\"headline\":\"Perfect Number In Java With Program Examples\",\"datePublished\":\"2022-08-23T07:28:36+00:00\",\"dateModified\":\"2022-08-23T07:56:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/\"},\"wordCount\":692,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Perfect-Number-In-Java-With-Source-Code-1.png\",\"keywords\":[\"java perfect number\"],\"articleSection\":[\"Java Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/\",\"name\":\"Perfect Number In Java With Program Examples - 2022 New\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Perfect-Number-In-Java-With-Source-Code-1.png\",\"datePublished\":\"2022-08-23T07:28:36+00:00\",\"dateModified\":\"2022-08-23T07:56:48+00:00\",\"description\":\"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Perfect-Number-In-Java-With-Source-Code-1.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Perfect-Number-In-Java-With-Source-Code-1.png\",\"width\":1460,\"height\":900,\"caption\":\"Perfect Number In Java With Source Code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/java-tutorial\\\/perfect-number-in-java-with-program-examples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Perfect Number In Java With Program Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/a1fb91e119811c0240699578286f83eb\",\"name\":\"Glenn Azuelo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314\",\"caption\":\"Glenn Azuelo\"},\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/glenn\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Perfect Number In Java With Program Examples - 2022 New","description":"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/","og_locale":"en_US","og_type":"article","og_title":"Perfect Number In Java With Program Examples","og_description":"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.","og_url":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/","og_site_name":"Itsourcecode.com","article_published_time":"2022-08-23T07:28:36+00:00","article_modified_time":"2022-08-23T07:56:48+00:00","og_image":[{"width":1460,"height":900,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png","type":"image\/png"}],"author":"Glenn Azuelo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Glenn Azuelo","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/"},"author":{"name":"Glenn Azuelo","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/a1fb91e119811c0240699578286f83eb"},"headline":"Perfect Number In Java With Program Examples","datePublished":"2022-08-23T07:28:36+00:00","dateModified":"2022-08-23T07:56:48+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/"},"wordCount":692,"commentCount":0,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png","keywords":["java perfect number"],"articleSection":["Java Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/","url":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/","name":"Perfect Number In Java With Program Examples - 2022 New","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png","datePublished":"2022-08-23T07:28:36+00:00","dateModified":"2022-08-23T07:56:48+00:00","description":"This article has a very detailed explanation about Perfect Number In Java. It helps you the easiest way with the best examples to guide you.","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Perfect-Number-In-Java-With-Source-Code-1.png","width":1460,"height":900,"caption":"Perfect Number In Java With Source Code"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/java-tutorial\/perfect-number-in-java-with-program-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"Perfect Number In Java With Program Examples"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/a1fb91e119811c0240699578286f83eb","name":"Glenn Azuelo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/4134d9c530ea2974454d3483e82db339.jpg?ver=1776441314","caption":"Glenn Azuelo"},"url":"https:\/\/itsourcecode.com\/author\/glenn\/"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/62567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/2342"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=62567"}],"version-history":[{"count":28,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/62567\/revisions"}],"predecessor-version":[{"id":76555,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/62567\/revisions\/76555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/62580"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=62567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=62567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=62567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}