1 回答
TA贡献1810条经验 获得超4个赞
需要进行一些更新,我已将其添加到评论中:
public class TriangleNumGenerator {
int counter;
int sides;
public TriangleNumGenerator(){
sides = 1;
counter = 2; // forgot ; here**
}
public int nextTri(){
sides = sides+counter;
counter = counter+1;
return sides;
}
public void reset(){
counter = 2;
sides = 1;
}
// you forgot main method; it has to be exactly same so that JVM
// can find it
public static void main(String[] args) {
TriangleNumGenerator ne = new TriangleNumGenerator();
System.out.println(ne.nextTri()); // forgot () in nextTri
}
}
这些是语法错误。如果您使用任何IDE,那么所有这些都应该报告!
添加回答
举报