Results 1 to 2 of 2
  1. #1
    xpngamer is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default Java Keeping Text in One Place

    I'm having trouble trying to have the text outputted in the console be in this format:

    Java Code:
    *                  Outputted Text                 *
    Where the text changes in length. Is there any way to center the text and
    keep the asterisk at the end in alignment with the others? Any help would be great.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    Use the String method length() to determine the length of the text in the heading and then calculate the number of spaces that must be used.

    (Instead of printing lots of spaces you can use the String method format() to align and pad the string "*" with spaces. But just printing a bunch of spaces is easier unless you are familiar with String.format() or the various printf() methods.)

Similar Threads

  1. Replies: 10
    Last Post: 02-28-2012, 08:44 PM
  2. Keeping track of Copies + Comparisons in Sort Methods
    By VinceGuad in forum New To Java
    Replies: 0
    Last Post: 03-12-2009, 04:07 AM
  3. how to place the controls >
    By makpandian in forum AWT / Swing
    Replies: 1
    Last Post: 12-18-2008, 06:17 AM
  4. Replies: 1
    Last Post: 08-27-2008, 04:27 AM
  5. Replies: 0
    Last Post: 07-31-2008, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts