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");
}
}
}

Line 5 - you seemed to mistyped "a" equal to zero for "a" equal to "o"

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.

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

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

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.

"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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.