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

  1. Calculate the length of the wire (or the maximum length of any line if it has multiple rows) -Maxlan
  2. Determine how much distance you want (it is called X)
  3. Length 2 + Maximum Allan + (2 * x) Output String
  4. Repeat step 4
  5. Output 2 stars max 4 + (2 * x)
  6. Output asterisk, space, string, SAPCE, asterisk
  7. Repeat step 3

You can extend it to get vertical spacing as well.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -