-6
我有以下两个语句:System.out.write不打印任何东西?
System.out.write(2); //Give nothing
System.out.print(2); //prints "2" in console
那么,为什么写的语句不写 - “2” - 在控制台?
我有以下两个语句:System.out.write不打印任何东西?
System.out.write(2); //Give nothing
System.out.print(2); //prints "2" in console
那么,为什么写的语句不写 - “2” - 在控制台?
首先,ASCII 2没有显示字形(这是一个特殊字符STK - 文本的开始)。使用char
文字。另外,您需要flush
。像,
System.out.write('2');
System.out.flush();
谢谢Elliott Frisch,我意识到我错过了冲水,并且只提到了冲水的一些注意事项。 –
你是否检查了[为PrintStream的API(http://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html)第一?一个字节写另一个字符 - 这是一个很大的区别。 –
PrintStream?为什么需要。我只是处理“System.out” –
@AsjadAzeez ...因为'System.out'是'PrintStream'类型。 Java中的所有东西都有一个类型。我建议阅读一些关于类型如何在Java中工作的教程。 – Qix