java - How to make a loop to center a string? -
How can I create a loop to create a location so that I can produce more space at least in places . The input string should be centered in the star. I can not understand this for loops how to do this. So if you can let me know why fix my code or fix it.
/ * ******* * * * * * *** * ****** * * * * * * * * * * * *
* Public static zero main (string [] args) instead of
* /
{// TODO code application logic here scanner keyboard = new scanner (System.in) ; System.out.print ("Enter a string:"); String word = keyboard. NixLine (); Int len = word.length (); For (int i = 0; i
I'm not sure whether you want only horizontal difference or both horizontal and vertical If you want only horizontal spacing, you can use the bottom
- Calculate the length of the wire (or the maximum length of any line if it has multiple rows) -Maxlan
- Determine how much distance you want (it is called X)
- Length 2 + Maximum Allan + (2 * x) Output String
- Repeat step 4
- Output 2 stars max 4 + (2 * x)
- Output asterisk, space, string, SAPCE, asterisk
- Repeat step 3
You can extend it to get vertical spacing as well.
Comments
Post a Comment