#Print the following series using while loop1 4 9 16 25 36 …. n

32 messages · Page 1 of 1 (latest)

potent imp
#

getting an error

vagrant abyssBOT
#

This post has been reserved for your question.

Hey @potent imp! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

potent imp
burnt heath
#

you are reassigning i, don't do that.

potent imp
#

trying with for loop

potent imp
burnt heath
#

yeah the for loop works because you are not assigning i*i to i, you are just printing it. If you delete your first statement in your while loop and change the System.out.print to match the one defined in your for-loop it will work

potent imp
burnt heath
burnt heath
potent imp
burnt heath
#

exactly doing the opposite.

burnt heath
potent imp
#

@burnt heath why it shows different output

burnt heath
#

because you are not reassigning i*i to i again. The right picture is the correct series implementation.

potent imp
burnt heath
#

check that i*i is smaller or equal to n

potent imp
#

?

burnt heath
#

don't need to use an if, you can change the condition of the while loop itself

burnt heath
#

the while loop, not the for loop

potent imp
#

like while()?

#

got it

#

thanks :}

vagrant abyssBOT
# potent imp thanks :}

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

potent imp
#

u are saviour bro :}

#

always helps me:]

#

🙏

#

have a nice day :}