class Perfect{
public static void main(){
long a[]=new long[10];
long n=1;
for(int i=0;i<10;i++){
while(true){
long sum=0;
for(long j=1;j<n;j++){
if(n%j==0){
sum+=j;
}
}
if(sum==n){
a[i]=n;
n++;
System.out.println("The array at turn "+i);
for(int v=0;v<a.length;v++)
{
System.out.println(a[v]+" ");
}
break;
}
n++;
}
}
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
}
}
I got a program as a part of my school project to create an array of size 10 and then fill this array with perfect numbers automatically in BlueJ. I wrote the above code however for some reason the code is running for 4 times only and then going on infinity and asking for inputs and not completing the 10 loops. Can someone please help me identify the problem. The code is in Java in BlueJ