+ 18

Why is this not printing the series

https://code.sololearn.com/c5UHII86YGo6/?ref=app

6th Aug 2020, 11:58 AM
Piyush
Piyush - avatar
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+" "); } }
7th Aug 2020, 11:05 AM
Josh Greig
Josh Greig - avatar
+ 7
Thanku so much Now I understand my mistake
7th Aug 2020, 11:28 AM
Piyush
Piyush - avatar