I have a menu in the program should look like this:

1. Add task: n -t 2. View all tasks: v 3. Add comment: n -c 

And so on...

I did this:

  System.out.printf("%-40s%-1s%n","1. Add task:","n -t"); System.out.printf("%-30s%-1s%n","2. View all tasks:","v"); System.out.printf("%-40s%-1s%n","3. Add comment:","n -c"); 

It turns out not that the indent from the first word is the same ... And the menu is still crooked ...

How to do it correctly so that it is exactly like in the first example?

    1 answer 1

    When substituting the second value, you indicated the addition with spaces on the right side, and you need the addition on the left side, i.e. without a minus. Try this:

      System.out.printf("%-40s%10s%n","1. Add task:","n -t"); System.out.printf("%-40s%10s%n","2. View all tasks:","v"); System.out.printf("%-40s%10s%n","3. Add comment:","n -c"); 

    And the console output will be like this:

     1. Add task: n -t 2. View all tasks: v 3. Add comment: n -c