简体   繁体   English

Java在新行中打印,我不需要

[英]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.

相关问题 我想通过命令行安装Java,但没有sudo访问权限。 - I want to install Java through the command line but I don't have sudo access. 如何在 Java 中将一个数组列表拆分为多个长度为 k 的数组列表? 我不想查看新列表,但我想创建它们 - How to split an arraylist in multiple arraylists of k lenght in Java ? I don't want a view of the new lists, but I want to create them 我在java中调用一个我无法控制的方法。 如果我没有得到它的回应,我想要杀死它并继续前进 - I'm calling a method in java which I have no control of. If I don't get a response from it, I want to kill it and move on 不明确的映射,我不想更改的相同 URL - Ambiguous mapping, same URLs which I don't want to change Java:AlertDialog无法打印新行 - Java: AlertDialog not printing new line 用Java在文件中打印新行 - Printing a new line in a file, in Java 在 java I/O 文件的新行中打印输出 - Printing output in new line in java I/O files 我不想在Java中重复代码Selenium - I don't want to repeat code selenium in Java MapStruct:如何过滤到我想要和不想映射的字段? - MapStruct: How can I do filter to fields which I want and don't want to mapping? Println 正在插入一个我不想要的额外行,“2 个换行符而不是 1 个” - Println is inserting an extra line that I don't want, “2 line breaks instead of 1”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM