Skip to main content

Simple print formatting question

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
snakeinmyboot
Offline
Joined: 2013-08-12

How can I get the data I display with the print function to display on the same indentation as seen in the attached picture?

Ive just been using spaces to accomplish this like

english: hello
french: bonjour
spanish: hola

surely there is away to tell the program to just print the data at a specific indentation without having to figure out how many spaces i need to put in there by eyeballing it.

Any advice?

:)

AttachmentSize
Screen_Shot_2013-09-19_at_11.24.28_AM.png24.05 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
DanielAlievsky
Offline
Joined: 2013-12-07

Try this:

class Test {
   public static void main(String [] args) {
      System.out.printf("%-20s %s%n", "1st:", "$10");
      System.out.printf("%-20s %s%n", "second:", "$100");
      System.out.printf("%-20s %s%n", "Very long string............:", "$10");
   }
}
snakeinmyboot
Offline
Joined: 2013-08-12

is anybody out there?

k_infinity
Offline
Joined: 2013-11-02

yep. but sorry there's no way as of now just stick to the power of spaces you got