      1  /**

      2     This program prints strings in boxes.

      3  */

      4  public class Boxes

      5  {

      6     public static void main(String[] args)

      7     {

      8        boxString("Hello");

      9        boxString("World");

     10     }

     11

     12     /**

     13        Prints a string in a box.

     14        @param str the string to print

     15     */

     16     public static void boxString(String str)

     17     {

     18        int n = str.length();

     19        // Print the top row

     20        for (int i = 0; i < n + 2; i++) { System.out.print("-"); }

     21        System.out.println();

     22        System.out.println("!" + str + "!");

     23        // Print the bottom row

     24        for (int i = 0; i < n + 2; i++) { System.out.print("-"); }

     25        System.out.println();

     26     }

     27  }