//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.");
}
}
}
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