0

program test whether the given integer is perfect or not


i dont know why there is some error and how to solve it?

class perfect
{
public static void main(String args[])
{
int a=o;
int n;
for(int i=1;i<=n;i++)
{

if(a==n)
System.out.print("Perfect number");
else
System.out.print("Not a Perfect number");
}
}
}

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

6
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Buffalo101
0

Also...
Line 7 - you never initialized n, so nothing will be done in here ==> no loop
Line 10 - Even you initialize n, you will never get this line to be printed out because a is 0 and n will never be 0 in order to get into the loop.

0

I think you need to compare a with i since i is your counter.

And by the way, what is a perfect integer??

0

this code makes no sense whatsoever-
1. what is a perfect integer?
2. n is not initialised. so it becomes 0, and the for loop will never be entered.
3. a=o, it should be a=0.

0

"Perfect" could be referring to a prime number or to a number with an integer root, I guess. Most likely he's trying to print something when he gets to his predesignated n number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.