Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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:

image text in transcribed

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

Students also viewed these Databases questions

Question

LO3 Define the difference between job satisfaction and engagement.

Answered: 1 week ago