Issue
I am working on a supply status dashboard and need to get my outputs in an aligned table. All arrays are populated with user input. Currently I have success with each output printing but only in a single column.
Code in question:
System.out.println();
System.out.println("Current status of all items being tracked:");
for (int index = 0; index < items.length; index++)
System.out.println(items[index] + " ");
for (int index = 0; index < items.length; index++)
System.out.println(supplyOnHand[index] + " ");
for (int index = 0; index < items.length; index++)
System.out.println(last24HourUsage[index] + " ");
Current output:
Current status of all items being tracked:
masks
hoods
Wipes
100
1000
10000
25
250
2500
Output wanted:
Current status of all items being tracked:
Masks 100 25
Hoods 1000 250
Wipes 10000 2500
I am unsure of how to exactly phrase the question and have come up empty.
Any specific help or general guidance to the required information would be helpful.
Thanks!
Solution
If you want to print in one line and your arrays are parallel you can just use one for loop and then concatenate all your values
for (int index = 0; index < items.length; index++)
System.out.println(items[index] + " " + supplyOnHand[index] + " " + last24HourUsage[index]);
If you want to align your text in columns you need to get the longest values in every array and then append multiple spaces depending on the amount of characters that are missing from your values
Answered By - AmNotSmort Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.