title: How to use print format to make box around text java?
body: <pre><code>public static void printBox(Scanner in, int length) {
      
      int spacesNeeded = 0;
      System.out.print("+"); 
      
      for (int i = 0; i &lt;= length + 1; i++) {
          System.out.print("-");
      } 
      
      System.out.print("+");    
      System.out.println();
          
      while (in.hasNext()) {
          System.out.println("| " + in.nextLine() + " |");
      } 
      
      System.out.print("+");
      
      for (int i = 0; i &lt;= length + 1; i++) {
          System.out.print("-");
      }
      
      System.out.print("+");    
      System.out.println();
      
  }
  </code></pre>
  
  <p>Above code makes a box like this:</p>
  
  <pre><code>+--------------+
  | This is some |
  | text here. |
  +--------------+
  </code></pre>
  
  <p>I need to find a better way to format this box and make the lines even with maybe a System.printf? or a better for loop process.</p>
  
  <p>End products needs to be:</p>
  
  <pre><code>+--------------+
  | This is some |
  | text here.   |
  +--------------+
  </code></pre>