page
WAP to check whether a no.
a perfect no. without twing
I do while,
Answers
Answered by
3
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;
____________________________
hope it helps you
Answered by
24
Here is your answer.
class x
{
static void main(int n)
{
int s=0;
for(int i=1;i<n;i++)
{
if(n%i==0)
s=s+i;
}
if(s==n)
System.out.println("Number is a perfect number. ");
else
System.out.println(" Number is not a perfect number. ");
}
}
Similar questions
English,
5 months ago
Computer Science,
5 months ago
Computer Science,
10 months ago
History,
10 months ago
Science,
1 year ago
Geography,
1 year ago
Math,
1 year ago