这个问题在这里已经有了答案:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(17 个回答)
5年前关闭。
我上课,由于某种原因,出现错误“找不到符号”
perimeter = width + length;
return perimeter;
我不确定为什么这里会出现错误(或者我的代码是否还有其他问题。我刚在学校开始使用 java,所以任何提示都会有所帮助。
/**
* A rectangle has a length and a width. Its perimeter can be calculated.
*/
public class Rectangle
{
private int length;
private int width;
/**
* Constructs a rectangle with a specified length and width
* @param len the length of the rectangle
* @param wid the width of the rectangle
*/
public Rectangle(int len, int wid )
{
length = 0;
width = 0;
}
/**
* Sets the length and width of the rectangle
* @param len the new length
* @param wid the new width
*/
public void setDimensions(int len, int wid)
{
length = len;
width = wid;
}
/**
* Returns the perimeter of the rectangle
* @return the perimeter of the rectangle
*/
public int calculatePerimeter( )
{
perimeter = width + length;
return perimeter;
}
最佳答案
perimeter
在那里找不到,因为它还没有被宣布。
要声明一个变量,您需要指定它的类型,然后是它的名称。
所以,例如,做...
int perimeter = width + length;
return perimeter;
关于java - 错误找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39927741/