• Post Reply Bookmark Topic Watch Topic
  • New Topic

Very beginner questions on loops  RSS feed

 
David Borchgrevink
Ranch Hand
Posts: 93
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully these haven't been answered before, but honestly I didn't even know what to search for. I am a beginner beginner beginner, and I can't stress that enough. I'm in my second week of an 8 month series with no prior programming knowledge whatsoever. The concepts have made complete sense thus far - it's just remembering the math needed and figuring out where to put it that's been most time consuming ( just turned 30, it's nowhere near fresh in my mind ).

That being said, I'm completely stuck like chuck on a few exercises, and need help. These aren't graded assignments or anything, just suggested activities. So I'm not necessarily just looking for the code so I can run along with it, but I AM a visual learner and usually learn best when I can see something paired with the problem to put two and two together.

Whew. Okay.

The first one I'm struggling with involves:

having the user enter 2 words,
print both words on one line,
separating the 2 words with enough dots between them so the total character length is 30.

I know I need to use a System.out.println(".") inside a loop body but I have no idea how, and the related chapter does nothing to explain this.



The second exercise involves:

having the user input an integer,
we then ask the user for THAT amount of integers and then find the sum, i.e.

How many integers will be added?
5
Enter an integer:
1
Enter an integer:
2
Enter an integer:
3
etc, etc.

Once again, the related chapter has no examples of how to perform this aside from use a counting loop.

I was going to ask about 1 more exercise, but this is a lot for one post, so I may wait until I can grasp the ideas and concepts behind these two.

Thanks in advance for any help at all! I need every bit I can get, for fear of falling behind so early in this series of classes is getting to me.
 
Louis Denning
Ranch Hand
Posts: 64
4
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this?

and this?
 
David Borchgrevink
Ranch Hand
Posts: 93
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Louis Denning wrote:Like this?

and this?


First, thanks so much for responding! So I'm not even going to venture into the second block you wrote before I can grasp the first. You threw me for a loop (no pun intended) with the "getUserInputSomehow" hah. That's how green I am, I thought you were naming something that. Then I see the stringOne and stringTwo and realize THOSE were the string names and I needed to use method scan.next() to retrieve the user input (not like you put a comment line saying exactly that or anything :P ). Putting "b" for the last print line instead of stringTwo almost got me, that was the first thing I caught

Thank you again so so much. I'm going to digest this and move to the next one. Hopefully if there's anything I need to fix/change I'll be able to figure it out and not get frustrated. glad I didn't get flamed for silly questions, very much appreciated
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Louis Denning wrote:Like this? . . .
No, no, no, no, no. Don't post full solutions. You would help much more by providing hints, and by seeing what is wrong with the OP's current code.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch David Borchgrevink
 
David Borchgrevink
Ranch Hand
Posts: 93
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Louis Denning wrote:Like this? . . .
No, no, no, no, no. Don't post full solutions. You would help much more by providing hints, and by seeing what is wrong with the OP's current code.


Sorry to cause a stir. I guess I did kind of ask for what it should look like. Hints probably would have pushed me in the right direction too though. Either way, thanks for the welcome!
 
Louis Denning
Ranch Hand
Posts: 64
4
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Borchgrevink wrote:First, thanks so much for responding! So I'm not even going to venture into the second block you wrote before I can grasp the first. You threw me for a loop (no pun intended) with the "getUserInputSomehow" hah. That's how green I am, I thought you were naming something that. Then I see the stringOne and stringTwo and realize THOSE were the string names and I needed to use method scan.next() to retrieve the user input (not like you put a comment line saying exactly that or anything :P ). Putting "b" for the last print line instead of stringTwo almost got me, that was the first thing I caught

Thank you again so so much. I'm going to digest this and move to the next one. Hopefully if there's anything I need to fix/change I'll be able to figure it out and not get frustrated. glad I didn't get flamed for silly questions, very much appreciated

Yeah, I thought that I should have changed the variable names to something more clear, but forgot to change some of them. Sorry~

Campbell Ritchie wrote:No, no, no, no, no. Don't post full solutions. You would help much more by providing hints, and by seeing what is wrong with the OP's current code.

I'm sorry D:
I thought it would be a good idea to explain each line...
...but I get what you mean and why.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted. and sorry myself because I overreacted a bit with the no, no, no.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!