我正在调用一个在我的控制台/标准输出中打印一些字符串的函数.我需要捕获这个字符串.我不能修改正在进行打印的函数,也不能通过继承来改变运行时行为.我无法找到任何允许我这样做的预定义方法.
JVM是否存储打印内容的缓冲区?
有谁知道有助于我的Java方法?
我正在为Javascript代码编写一些测试,我需要在遇到错误时在编译过程中转储一些消息.
System.out.println()在Javascript中有没有相当于Java的东西?
PS:我还需要在实现测试时转储调试语句.
UPDATE
我在包含所有合并测试的文件上使用maven插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.mozilla.javascript.tools.shell.Main</mainClass>
<arguments>
<argument>-opt</argument>
<argument>-1</argument>
<argument>${basedir}/src/main/webapp/html/js/test/test.js</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
更新II
我试过了console.log("..."),但我明白了:
js: "src/main/webapp/html/js/concat/tests_all.js", line 147:
uncaught JavaScript runtime exception: ReferenceError: "console" is not defined
Run Code Online (Sandbox Code Playgroud)
我正在测试的代码是一组函数(比如在库中).我正在使用QUnit.
我正在使用IntelliJ IDEA,学习Java.直到昨天发生上述错误时,一切顺利.
我没有做任何改变.我正在寻找以下方法的解决方案:
无济于事.买跑步简单的你好世界的方法.它一直显示此错误:
有人能帮助我吗?
我有一个程序打印出应该打印成看起来像表的格式的数据.但是,当数字长于2时,表会中断.我知道width参数std::fmt,但是我无法理解它.
当前输出:
---------------------------------------
| total | blanks: | comments: | code: |
---------------------------------------
| 0 | 0 | 0 | 0 |
| 77 | 0 | 3 | 74 |
| 112 | 0 | 6 | 106 |
| 178 | 0 | 6 | 172 |
| 218 | 0 | 7 | 211 |
| 289 | 0 | 8 | 281 |
| 380 | 0 | 9 | 371 | …Run Code Online (Sandbox Code Playgroud) 我有一个疑问如下.
public static void main(String[] args) throws IOException{
int number=1;
System.out.println("M"+number+1);
}
Run Code Online (Sandbox Code Playgroud)
输出: M11
但我想把它打印成M2而不是M11.我无法对++进行编号,因为变量与for循环有关,如果我这样做会给我不同的结果,并且无法使用另一个print语句打印它,因为输出格式会发生变化.
请求您帮我正确打印.
我想它与新println()行功能('\n')相关,但是在缩写的基于字母的形式中,这nl不是ln.谢谢你的任何评论.
use std::collections::HashMap;
fn main() {
let mut hash = HashMap::new();
hash.insert("Daniel", "798-1364");
println!("{}", hash);
}
Run Code Online (Sandbox Code Playgroud)
不会编译错误
特征绑定std :: collections :: HashMap <&str,&str>:std :: fmt ::显示不满意
有没有办法说出类似的话:
error[E0277]: `std::collections::HashMap<&str, &str>` doesn't implement `std::fmt::Display`
--> src/main.rs:6:20
|
6 | println!("{}", hash);
| ^^^^ `std::collections::HashMap<&str, &str>` cannot be formatted with the default formatter
|
Run Code Online (Sandbox Code Playgroud)
打印出来:
println!("{}", hash.inspect());
Run Code Online (Sandbox Code Playgroud) 波纹管代码:
scala> class A {
| def hi = "Hello from A"
| override def toString = getClass.getName
| }
defined class A
scala> val a = new A()
a: A = A
scala> a.toString
res10: String = A
scala> println(s"${a.toString}")
$line31.$read$$iw$$iw$A
Run Code Online (Sandbox Code Playgroud)
使用a.toString表达式时打印正常,而不是在使用时打印println(s"${a.toString}").问题是getClass.getName.在其他情况下,它很好用.
在此先感谢您的帮助
如何在10行打印n个(例如10个)数字列表?我刚刚得知循环和复发,但似乎无法副作用结合(println i)与(recur (+ i 1))在一个循环的形式.只是要非常清楚:我想要像这样的输出:
1
2
3
4
5
6
7
8
9
10
Run Code Online (Sandbox Code Playgroud)
当n为10时.
在Swift中使用println和print打印到控制台.但它们之间的唯一区别似乎是println返回到下一行而print不是.
例如:
println("hello world")
println("another world")
Run Code Online (Sandbox Code Playgroud)
将输出以下两行:
hello world
another world
Run Code Online (Sandbox Code Playgroud)
而:
print("hello")
print("world")
Run Code Online (Sandbox Code Playgroud)
只输出一行:
helloworld
Run Code Online (Sandbox Code Playgroud)
这print似乎更像是printfC中的传统.Swift文档说明println了相当于NSLog但目的print是什么,除了不返回下一行之外,有没有理由使用它?