gpt4 book ai didi

Java:更容易 pretty-print ?

转载 作者:搜寻专家 更新时间:2023-10-30 21:43:29 26 4
gpt4 key购买 nike

在我的计算结束时,我打印结果:

System.out.println("\nTree\t\tOdds of being by the sought author");

for (ParseTree pt : testTrees) {
conditionalProbs = reg.classify(pt.features());

System.out.printf("%s\t\t%f", pt.toString(), conditionalProbs[1]);
System.out.println();
}

例如,这会产生:

Tree  Odds of being by the sought author
K and Burstner 0.000000
how is babby formed answer 0.005170
Mary is in heat 0.999988
Prelim 1.000000

只是将两个 \t 放在那里有点笨拙——这些列并没有真正对齐。我宁愿有这样的输出:

Tree                         Odds of being by the sought author
K and Burstner 0.000000
how is babby formed answer 0.005170
Mary is in heat 0.999988
Prelim 1.000000

(注意:我无法让 SO 文本编辑器完美地排列这些列,但希望你明白了。)

有没有一种简单的方法可以做到这一点,或者我是否必须编写一种方法来尝试根据“树”列中字符串的长度来计算它?

最佳答案

您正在寻找字段长度。尝试使用这个:

printf ("%-32s %f\n", pt.toString(), conditionalProbs[1])

-32 告诉您字符串应该左对齐,但字段长度为 32 个字符(根据您的喜好调整,我选择 32,因为它是 8 的倍数,这是终端上的正常制表位).在 header 上使用相同的内容,但使用 %s 而不是 %f 也会使这一行很好。

关于Java:更容易 pretty-print ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1875936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com