Program To Print Perfect Number JAVA


Write a Program to print whether the inputted number is Perfect or not.




[A number whose sum of factors (excluding the number itself) is equal to the number is called a perfect number. Example : 6]


import java.util.*;
class perfect
{
    public static void main(String args[])
    {
     Scanner sc = new Scanner (System.in);
     int n = sc.nextInt();
     int sum = 0;
     for (int i =1; i< n;i++)
     {
        if(n % i == 0)
        {
          sum = sum + i;
        }
     }
     if (sum == n)
     {
         System.out.println("It is perfect no");
     }
     else
     {
       System.out.println("It is not perfect no");  
     }
     
 }
}

     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com