I wrote this java program for printing all three digit perfect numbers, however it doesn't print anything except "PERFECT NUMBERS" and "Total : 0". Arrays and functions not allowed (school assignment).
class PerFect
{
public static void main(String args[])
{
int num, i, sum=0, total=0;
System.out.println("PERFECT NUMBERS : ");
for(num=100; num<=999; num++)
{
for(i=1; i<=num; i++)
{
if(num%i==0)
sum=sum+i;
}
if(num*2==sum)
{
System.out.println(num);
sum=0;
total++;
}
}
System.out.println("Total : "+total);
}
}