java - 错误找不到符号

标签 java compiler-errors

这个问题在这里已经有了答案:





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/

相关文章:

Android 构建错误

C#:指向 double 的指针

java - Android - HTTPURLConnection 在发布多个输入时失败

java - 基于区域设置的 Joda-Time DateTime 格式

java - 由于 Java 无法运行 SDK Manager

java - Java中使用Optional类时,对象无法转换为字符串

c++ - 递归 boost::variant 类型不能用 "-std=c++11 -stdlib=libc++"编译

c++ - 关于 Qt4 setValidator 用法的莫名其妙的 gcc 投诉

c - 无法使用make编译C源文件。 CMake错误找不到源文件,但它们在那里

Java - 无法编辑字节数组内容?