Write a program in java to accept an integer, compute and check whether it is a perfect number or not. A number is
known as perfect number, if the sum of factors (excluding the number) is equal to the number. eg. 6=1+2+3.
Answers
Answered by
2
Answer:
Java Program to Check if a given Number is Perfect Number
public class Perfect.
int n, sum = 0;
Scanner s = new Scanner(System.
System. out. print("Enter any integer you want to check:");
n = s. nextInt();
for(int i = 1; i < n; i++)
if(n % i == 0)
sum = sum + i;
Similar questions