I'm trying to format two arrays in Java to print something like this:
Inventory Number Books Prices
------------------------------------------------------------------
1 Intro to Java $45.99
2 Intro to C++ $89.34
3 Design Patterns $100.00
4 Perl $25.00
I am using the following code:
for(int i = 0; i < 4; i++) {
System.out.print(i+1);
System.out.print(" " + books[i] + " ");
System.out.print(" " + "$" + booksPrices[i] + " ");
System.out.print("\n");
}
But I am getting this poorly formatted result instead:
Inventory Number Books Prices
------------------------------------------------------------------
1 Intro to Java $45.99
2 Intro to C++ $89.34
3 Design Patterns $100.0
4 Perl $25.0
How would I go about lining all the columns up directly under the headers at the top?
Is there a better way to go about doing this?
\t. Eg.:System.out.println(String.format("\t %s", books[i]);And for a double tab, use \t\t and so on as many as you want