[英]Java printing in new line, which I don't want
for (int numToCheck = start; numToCheck < numSteps*increment + start;
numToCheck += increment)
{
System.out.println(numToCheck+"\t");
String tekst = getStringFromFile(textfile, numToCheck);
double beg1 = System.currentTimeMillis();
for(int i = 0; i<trials; i++) {
BasicDocument doc = new BasicDocument(tekst);
doc.getFleschScore();
}
double time1 = System.currentTimeMillis() - beg1;
System.out.println(time1+"\t");
double beg2 = System.currentTimeMillis();
for(int i = 0; i<trials; i++) {
EfficientDocument doc2 = new EfficientDocument(tekst);
doc2.getFleschScore();
}
double time2 = System.currentTimeMillis() - beg2;
System.out.println (time2);
This is the code I'm running, and the results are printed in new lines, not separated by tabs (\\t). 这是我正在运行的代码,结果打印在新行中,而不用制表符(\\ t)分隔。
What am I not understanding? 我不明白什么?
Also, anything else you can give me advice about, I have started programming just recently, does the code look good? 另外,您还有其他建议,我最近才开始编程,代码看起来不错吗?
Use 采用
System.out.print()
not 不
System.out.println()
From the doc of println()
来自println()
的文档
Terminates the current line by writing the line separator string. 通过写入行分隔符字符串来终止当前行。 The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\\n'). 行分隔符字符串由系统属性line.separator定义,不一定是单个换行符('\\ n')。
Change 更改
System.out.println(time1+"\t");
to 至
System.out.print(time1+"\t");
println
always adds a newline. println
总是添加换行符。
Use System.out.print()
with \\t
将System.out.print()
与\\t
\\t
will add a tab and print()
method will print on the same line so you will be having your output separated by tab. \\t
将添加一个制表符,并且print()
方法将在同一行上打印,因此您将使用制表符分隔输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.