class Demo2
{
int i=1,j=2;
void fun1()
{
i=i+1;
j=j+1;
}
public static void main(String[] args)
{
Demo2 d1=new Demo2();
d1.fun1();
d1.fun1();
d1.fun1();
System.out.println("Hello World!");
}
}
符号无法找到并且功能无法应用错误显示请帮助我,我是一个基础学习者......
最佳答案
代码中有几个错误。我评论并建议了一些工作代码。
class Demo2
{
void fun1()
{
i=i+1; //i has not been initialized
j=j+1; //j has not been initialized
}
public static void main(String[] args)
{
Demo2 d1=new Demo2();
d1.fun1(1);//"fun1" does not accept a parameter.
d1.fun1();
d1.fun1();
System.out.println("Hello World!");
}
}
这里是一个可以运行的 Demo2 类,可以帮助您:
class Demo2
{
int i = 0;
int j = 0;
public void fun1(int param)
{
i=i+param;
j=j+param;
}
public static void main(String[] args)
{
Demo2 d = new Demo2();
d.fun1(1);//adds 1 to both i and j
d.fun1(2);//adds 2 to both i and j
System.out.println("i is equal to " + i);
System.out.println("j is equal to " + j);
}
}
关于java - 找不到符号且函数无法应用: Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20665218/