简体   繁体   English

Java(Eclim + Vim)“ system.out.print”不起作用

[英]Java (Eclim + Vim) “system.out.print” not working

I am new to Java programming, and today while messing with eclim and vim, I discovered that the System.out.println(); 我是Java编程的新手,而今天,在碰到eclim和vim时,我发现System.out.println(); function is not working. 功能不起作用。

class apples{
public static void main(String args[]){
    double tuna = 5.28;
    System.out.print(tuna);
}
}

This does not give me a result. 这没有给我结果。

But when I do: 但是当我这样做时:

class apples{
public static void main(String args[]){
    double tuna = 5.28;
    System.out.println(tuna);
}
}

(The only difference is the "println") I get 5.28, the correct behavior. (唯一的区别是“ println”)我得到了5.28,正确的行为。

Anyone know why this would happen, or is this the way it should be happening? 任何人都知道为什么会发生这种情况,或者这是应该发生的方式吗?

.println() automatically appends a newline, .print() does not. .println()自动添加换行符, .print()不会。

System.out is a buffered stream; System.out是一个缓冲的流; you need to .flush() for the result of .print() to appear (do it after you print, obviously). 您需要使用.flush()才能显示.print()的结果.print()显然是打印执行)。 The newline in .println() causes the output to be flushed, which is why you don't need it there. .println()的换行符导致输出被刷新,这就是为什么您在那里不需要它的原因。

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

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