#Print the following series using while loop1 4 9 16 25 36 …. n
32 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @potent imp! Please use
/closeor theClose Postbutton 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.
you are reassigning i, don't do that.
trying with for loop
showing error
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
it should stop at 49
you currently tell the program to print 49 elements of the series, not to stop at 49
i is not declared here
u mean to type i=i * i then print?
exactly doing the opposite.
this code is correct. Just transfer your for loop to a while loop
@burnt heath why it shows different output
because you are not reassigning i*i to i again. The right picture is the correct series implementation.
ohh so how can i stop that to 49 using while loop?
check that i*i is smaller or equal to n
umm so i have to type if(i*i<=n) {}
?
don't need to use an if, you can change the condition of the while loop itself
apply this to for loop?
the while loop, not the for loop
can u plz write what change i have to do ?
like while()?
got it
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.