Home / Blue J / Program in Java to find whether a number is perfect or not

Program in Java to find whether a number is perfect or not

Perfect Number-  If the sum of all the factors of a number is equal to the number itself then it is a perfect number. This program finds whether a given number is perfect number or not.

Example:- 6 = 1+2+3

28 = 1+2+4+7+14

import java.io.*;
class perfectnumber
{
public static void main()throws IOException
{
int n,s=0;
InputStreamReader IR=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(IR);
System.out.println("entre a no");
n=Integer.parseInt(br.readLine());

for(int x=1;x<n;x++)
if(n%x==0)
s=s+x;
if(s==n)
System.out.println("it is perfect no");
else
System.out.println("it is not perfect no");
}
}

OUTPUT:

program to check perfect number

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

One comment

  1. Cool is so ccool

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.