为什么我在Java中收到此错误?

时间:2018-07-01 13:09:21

标签: java

  

线程[main](被挂起(方法printf(String,int,int)是   对于PF类型未定义))

import acm.program.*;

public class PF extends ConsoleProgram    
{

        public void run() {

        int x = 4;

        int Y= 17;


        printf("x is %d and Y is %d",x,Y);

    }

}

3 个答案:

答案 0 :(得分:2)

您需要像这样使用它:

System.out.printf("x is %d and Y is %d", x, Y);

没有其类名就无法调用printf静态函数

或者:

System.out.println(String.format("x is %d and Y is %d", x, Y));

答案 1 :(得分:1)

使用System.out.printf

System.out.printf("x is %d and Y is %d",x,Y);

答案 2 :(得分:0)

假设您尝试使用acm.program库,则问题在于 库中的任何地方都没有定义printf方法。

当然,不是在https://www-cs-faculty.stanford.edu/people/eroberts/jtf/版本2.0中描述的。

您需要坚持使用ConsoleProgram class实际定义的方法。


我的建议是除非明确指示/要求您不要使用此库。从长远来看,您最好学习使用标准Java库。

相关问题