We are uploading our contents, please refresh app.
Java Premium

write a Program in java to accept a number from the user and check whether it is a Perfect number or not.

Perfect number – a number is called a Perfect number if it is equal to the sum of its factors other
than the number itself. Example: 6 = 1 + 2 + 3.

Program: 
import java.util.*;
class Perfect_Number
{
public static void main(String[] args) 
{
int n,i,s=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
n=sc.nextInt();
for(i=0;i<n;i++)
{
  if(i%2==0)
    s=s+i;
}
if(n==s)
{
  System.out.println("Entered number is perfect");
}
else
 System.out.println("Entered number is not perfect"); 
}
}

Output:
Enter the number: 
6
Entered number is perfect

Enter the number: 
16
Entered number is not perfect

Online user

Download our android app Download App Submit your query
x

Get Updates On

Java & Premium Programs

Java Solved & Questions

Java Coding easy to use

Proper Coding

Straight Into Your INBOX!

We are going to send you our resources for free. To collect your copy at first, join our mailing list. We are promising not to bother you by sending useless information. So don't miss any updates, stay connected!