11y Wap to accept no. and check whether it is perfect or not
Answers
Answered by
1
Answer:
// Java program to check whether the given number is a perfect number or not
import java.util.*;
public class Main{
public static void main(String[ ] args)
{
Scanner sc = new Scanner(System.in);
System.out.print(“Enter a number : “);
int num = sc.nextInt();
int i, sum = 0;
for(i=1; i<num; i++)
{
if(num%i == 0)
{
sum += i;
}
}
if(sum == num)
{
System.out.print(num + ” is a Perfect Number\n”);
}
else
{
System.out.print(num + ” is not a Perfect Number\n”);
}
}
}
Similar questions