+ 18
Why is this not printing the series
2 Answers
+ 3
I don't know what kind of series you want to print but you're getting an infinite loop because you change variable i back to 0 nested in a for-loop that won't end until i reaches a larger number.
Note that your indentation is misleading. Proper indentation will help you see the "i=i/10;" is repeated until i is 0 which stops the for-loop from ever completing.
for(int i=1;i<=n;i++)
{
a=i;
int sum=0;
while(i>0)
{
r=i%10;
sum=sum+(r*r*r);
i=i/10;
}
if(sum==a)
{
System.out.print(a+" ");
}
}
+ 7
Thanku so much
Now I understand my mistake