Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enought dots so that the total line length is 30:
Enter first word:
turtle
Enter second word
153
turtle....................153
This could be used as part of an index for a book. To print out the dots, use System.out.print(".") inside a loop body.
and I know to use a while loop, but not much else. This is what I have:
*********************
I know I need to use inputString.length() I just don't know where.
So you can get the two lengths, right? And you know you need 30 characters total.
What's the next step?
(Btw, please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.)
Theresa Marlin
Ranch Hand
Joined: Sep 23, 2009
Posts: 49
posted
0
So, I get the lengths of firstWord and secondWord, and then put that into a variable? then, while ((firstWord + secondWord) < 30) count = count + 1 and then print the number of ....'s for counts?
Thanks!!!
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
4
posted
0
Theresa Marlin wrote: . . ., while ((firstWord + secondWord) < 30) count = count + 1 and then print the number of ....'s for counts?
That is one way to do it. You will get better performance with a StringBuilder and adding one . at a time, because adding to a StringBuilder is very fast and printing is slow.
Theresa Marlin
Ranch Hand
Joined: Sep 23, 2009
Posts: 49
posted
0
Thank you, but since I do not know StringBuilder yet, I should probably stick with what I do know.
Thank you all for your help!!!