排队在控制台输出的Java数据控制台、数据、Java

2023-09-11 07:56:08 作者:毛骨悚男,)

我有以下code以下提取;

问题是,

 (element.getChildNodes()项目(0).getNodeValue())
 

具有字符的不同数目的输出

然后使 eventy 要移动的脱节与因此给数据而不是列中数据的锯齿形外观的其他行其他的输出,我已经尝试过尝试用制表符和空格。但是,将AP preciate一些帮助,请。

 字符串eventy = NULL;

的for(int i = 0; I< list.getLength();我++){
    element元素=(元)list.item(我);
    字符串节点名称= element.getNodeName();

    开关(节点名称){
        案ASSD:
            (。(element.getChildNodes()项目(0).getNodeValue())+\ t的eventy)的System.out.println;
            打破;
        案eventy:
            。eventy = element.getChildNodes()项目(0).getNodeValue();
            打破;
    }
}
 

解决方案 实体店如何利用 接触效应 赚钱 一个实验告诉你

如果你可以假设从ASSD子节点,你可以使用 System.out.printf 。例如:

  System.out.printf(% -  20秒%S%N,element.getChildNodes()项目(0).getNodeValue(),eventy)
 

将打印ASSD子节点的值与变量 eventy ,然后换行分隔符宽度20则值第一列。

请参阅格式字符串语法

I have the following extract of code below;

The issue is that

(element.getChildNodes().item(0).getNodeValue())

has output of a differing number of characters

which then causes eventy to be moved out of line with other output from the other rows therefore giving a zig zag appearance of data instead of data in columns, i have tried experimenting with tabs and spaces. But would appreciate some help please.

String eventy = null;

for (int i = 0; i < list.getLength(); i++) {
    Element element = (Element)list.item(i);
    String nodeName = element.getNodeName();

    switch (nodeName) {
        case "assd":
            System.out.println((element.getChildNodes().item(0).getNodeValue()) + "\t  " eventy);
            break;
        case "eventy":
            eventy = element.getChildNodes().item(0).getNodeValue();
            break;
    }
}

解决方案

If you can assume maximum length of strings from "assd" child node, you could use System.out.printf. For example:

System.out.printf("%-20s   %s%n", element.getChildNodes().item(0).getNodeValue(), eventy)

would print a value of "assd" child node to first column with width 20 then value of variable eventy and then new line separator.

See Format String Syntax