如何修复此声明?
System.out.printf(" 1 | %d | %d | %d\n" ,
Simulator.simulate(2, 1, 0.71, 15, 1200),
Simulator.simulate(5, 1, 0.71, 15, 1200),
Simulator.simulate(10, 1, 0.71, 15, 1200)
);
Syntax error on token ".", { expected after this token [. in Simulator.simulate]
Syntax error on token "" 1 | %d | %d | %d\n"", invalid FormalParameterList
答案 0 :(得分:0)
以下代码会创建完全相同的错误(以及更多错误)
public class Analyzer {
System.out.printf(" 1 | %d | %d | %d\n" ,
Simulator.simulate(2, 1, 0.71, 15, 1200),
Simulator.simulate(5, 1, 0.71, 15, 1200),
Simulator.simulate(10, 1, 0.71, 15, 1200)
);
}
类主体中的方法调用System.out.printf
不允许。在方法,构造函数或静态初始化程序中移动它:
public class Analyzer {
static {
System.out.printf(" 1 | %d | %d | %d\n" ,
Simulator.simulate(2, 1, 0.71, 15, 1200),
Simulator.simulate(5, 1, 0.71, 15, 1200),
Simulator.simulate(10, 1, 0.71, 15, 1200)
);
}
}