Sunday 16 August 2015

WAP in java to check whether the entered no is perfect or not.

//To check no is perfect or not

import java.util.Scanner;

public class Perfect {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter a no:");
int no=sc.nextInt();

if (no%2!=0)
System.out.println("It is not a perfect no.");
else
{
int n=0;

for(int i=1;i<no;i++)
{
if(no%i==0)
n=n+i;
}

if(n==no)
System.out.println("It is a perfect no.");
else
System.out.println("It is not a perfect no.");
}


}

}

No comments:

Post a Comment