Question
How to add right aligned spaces to make ascii table line up properly when using System.out.printf()? I am trying to print an ascii table that
How to add right aligned spaces to make ascii table line up properly when using System.out.printf()?
I am trying to print an ascii table that requires me to use System.out.printf(); and input from a 2-dimensional array.
The array has 3 columns and 8 rows and contains these values.
10 1 2 100 0 1 1000 0 2 10000 1 3 100000 6 27 1000000 46 53 10000000 105 1192 100000000 954 11261
When trying to print the table with this method:
public static void print2dAsciiTable( long[][] data ) { String spacer = "+---------------+-----------+-----------+ "; System.out.printf( spacer ); for (int row = 0; row
System.out.printf( spacer ); } }
I get this output:
How can I make it line up properly to have many spaces on the left of each number in the first column with only 2 buffer spaces on the right side like it currently has?
I need the output to resemble this:
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started