Welcome to The Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads

Need some java help


Zeused
 Share

Recommended Posts

I am currently learning loops (just finished for loops, or at least the basics of it) and working on while loops. was wondering if someone could help me out? (must be used with while loop, even though it can be solved with for loop).

07bR3QY.png

it is pretty basic, but anything relating to while loops really flies over my head.

integer n is equal to the amount of stars are returned, so the returning value is a string and I think it will continue on at an infinite rate, although idk if codingbat will enjoy that.

ive been using cloud9 (although support is gone at 2020) so I don't mind hardcoding it as well.

Link to comment
Share on other sites

  • 3 weeks later...

sort of a late reply but ive got another problem lol.

I did some editing from your setup and came up with this (which worked). I don't think codingbat liked the infinite loop, so it would say "timed out", so I had to limit it.

String output = ""; 
int i = 0;
while (i < n) { 
output = output + "*";
i = i+1;

return output;
}

anyways ive got another problem, and yet again it returns a string.

this one is a little harder, but I can use for loops for it, but the input is a string. (ive never used strings for an input in a for loop before, just integers and doubles)

coDXVFu.png

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share