简体   繁体   English

你如何让并行的用户输入数组在java中的对齐表中打印?

[英]How do you get parallel user input arrays to print in an aligned table in java?

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!谢谢!

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 循环,然后连接你的所有值

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如果要在列中对齐文本,则需要获取每个数组中最长的值,然后根据值中缺少的字符数量附加多个空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM