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 Using pure (Return) Function.

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_pure_fun
{
  public int fun(int n)
  {
    int s=0,i;
    for(i=0;i<n;i++)
{
  if(i%2==0)
    s=s+i;
}
return(s);
  }
  public static void main(String[] args) 
{
int no,p;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
no=sc.nextInt();
Perfect_pure_fun obj=new Perfect_pure_fun();
p=obj.fun(no);
if(p==no)
{
  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: 
6
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!