[英]whats wrong with my simple code
我正在尝试运行这个简单的代码,但它仍然给我错误,即令牌上的系统错误','; 预计在线; int blackbox.Area();
package box;
public class box {
int height;
int width;
enter code here
public int Area(){
return height*width;
}
box blackbox= new box();
public void main(){
blackbox.height = 3;
blackbox.width= 4;
int blackbox.Area();
}
}
public void main(){
blackbox.height = 3;
blackbox.width= 4;
int val = blackbox.Area(); // -> 5 line
}
您的方法正在返回一个值,因此您可能需要另一个变量来捕获它。 第 5 行有语法错误。
我同意汤姆的看法。 您需要更具体的方法来解决问题。 您可以通过多种方式完成。 由于您是初学者,因此可以通过制作 2 个课程来简单地完成。
BoxAreaFinder.java
public class BoxAreaFinder {
public static void main(String[] args) {
Box blackbox = new Box();
blackbox.height = 3;
blackbox.width = 4;
int areaOfBlackBox = blackbox.Area();
System.out.println(areaOfBlackBox);
}
}
盒子.java
public class Box {
int height;
int width;
public int Area() {
return height * width;
}
}
输出: 12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.