Write a program in java to find out if a number is a perfect number or not?
Answers
Answered by
2
Answer:
Java Program to Check if a given Number is Perfect Number. ... A perfect number is a positive integer that is equal to the sum of its proper positive divisors excluding the number itself. Enter any integer as an input.
Answered by
8
Question:
Write a program in Java to find out if a number is a perfect number or not.
Answer:
import java.until*;
public class perfectnum
{
public static void main (string [ ] args)
{
int sum=0,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int a=sc.nextInt();
for(i=1;i<=n;i++)
{
if(num%i==0)
sum=sum+i;
if(num%num==0)
continue;
System.out.println("It's a perfect number");
}
System.out.println("not a perfect number");
}
}
_______________________________
Similar questions