1
 for (int k = 0; k < 7; k++){
        System.out.println("Vak/project:\t" + vakNamen[x] + "\t\t"
        + "Cijfer: " + vakCijfers[x] + "\t" + "Behaalde punten: "
        + vakPunten[x]);
        x++;
    }

EDIT: the assignment wants to use system.out.printf so I will have a look at that, ty for the hint

and the system.out.format seems interesting I never heard of that, will look into it

Ok so my question is in this for loop I print 3 different arrays and I want them to be in a table so I used \t, but the problem u get with this is that if the "vakNamen" which is the name of the subject is LONGER than another then the tabs will go further and create this ugly table:

https://gyazo.com/398953f233f3562eecfa6c483ec73e62

I dont really know how to ask this question but I think I should ask how to make sure \t is independant from the previous lines?

StanlyGoodLife
  • 33
  • 1
  • 2
  • 6
  • 3
    You should have a look at `System.out.printf` and its [formats](https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) – BackSlash Nov 01 '17 at 11:16
  • I would advise you to either use csv format by using comma separation instead of tabs. But if you really want to use tabs then you might want to base the tabs upon the largest value that your column has. For example you might need to use double or even triple tabs to separate the columns instead of just one tab. – Kainda Nov 01 '17 at 11:18
  • I guess this will answer your question: [Stackoverflow](https://stackoverflow.com/questions/2745206/output-in-a-table-format-in-javas-system-out) – Michael Hegner Nov 01 '17 at 11:22

1 Answers1

4

You can use System.out.format()

Example:

String project = "myProjectName";
String firstName = "firstName";
String lastName = "lastName";

System.out.format("%-20s%-15s%-15s", project, firstName, lastName);

Above code snippet should print the following formatted output:

myProjectName       firstName      lastName  

Edit:
I found this library which simplifies such kind of formatting. It is also available on Maven.

Lakshmikant Deshpande
  • 826
  • 1
  • 12
  • 30