Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java FormalParameterList无效,令牌“0”上出现语法错误&引用;,{应在该令牌之后_Java - Fatal编程技术网

Java FormalParameterList无效,令牌“0”上出现语法错误&引用;,{应在该令牌之后

Java FormalParameterList无效,令牌“0”上出现语法错误&引用;,{应在该令牌之后,java,Java,如何修复此语句 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,

如何修复此语句

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)      
              );
   }
}

编译时错误?原因可能在此语句之外。可能您遗漏了某个
{
}
。您在其他地方有语法错误,该特定行没有问题,因为这就是调用
printf()
的方式,请仔细检查语句是否(1)在方法内,(2)在构造函数内部或(3)在静态初始值设定项中。类似的错误表示某些语句是在方法外部编写的…它在公共类分析器内部
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)      
              );
}
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)      
              );
   }
}