Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2016
    Posts
    93
    Rep Power
    0

    Default Strange indentation output in console

    The console output has inconsistent indentation in the String message, and I don't know why:
    Strange indentation output in console-javaindentationproblem.png

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Strange indentation output in console

    The whitespace in the Strings ("Subtotal: ", etc), are those spaces or tabs?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Join Date
    Mar 2016
    Posts
    93
    Rep Power
    0

    Default Re: Strange indentation output in console

    Quote Originally Posted by SurfMan View Post
    The whitespace in the Strings ("Subtotal: ", etc), are those spaces or tabs?
    Tabs. Why?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Strange indentation output in console

    Quote Originally Posted by SurfMan View Post
    The whitespace in the Strings ("Subtotal: ", etc), are those spaces or tabs?
    My guess is that they're tabs: look at the indentation of the code: that tabs space seems to be four characters, while the tabs expand to eight spaces in a console. No matter what: it's a bad idea: proportional fonts ruin everything while a fixed width font together with different tab sizes can show results as the above.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Strange indentation output in console

    Quote Originally Posted by Sam_JavaTheHut5580 View Post
    Tabs. Why?
    There's your answer. Change them to spaces.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Strange indentation output in console

    Perhaps you should use System.out.printf(). It behaves similar to the C print statement. You can provide
    field width modifiers to your format string to control data alignment. It is much easier and less error prone
    than your method.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Reading output from console
    By Maygs in forum New To Java
    Replies: 2
    Last Post: 06-14-2013, 06:33 AM
  2. Getting a very strange output..
    By jubbiejub in forum New To Java
    Replies: 4
    Last Post: 04-06-2012, 04:12 AM
  3. output to terminal instead of console on mac
    By firen in forum Advanced Java
    Replies: 0
    Last Post: 06-01-2010, 12:42 PM
  4. How Do You?? Get the Console Output as a GUI??
    By Lyricid in forum AWT / Swing
    Replies: 10
    Last Post: 11-20-2009, 11:35 PM
  5. How to align the output on console?
    By sfe23 in forum New To Java
    Replies: 5
    Last Post: 03-30-2009, 03:28 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
  •