2016-10-08 14 views
-2

je faire une classe et pour une raison quelconque, il est l'erreur « ne peut pas trouver le symbole » pourerreur ne peut pas trouver le symbole

perimeter = width + length; 
return perimeter; 

Je ne sais pas pourquoi une erreur ne devrait se produire (ou s'il y a quelque chose d'autre mal avec mon code. Je viens de commencer java à l'école si des conseils seraient utiles.

/** 
* 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; 
} 
+3

'parameter' est jamais définie? – Li357

Répondre

3

perimeter ne peut y être trouvé parce qu'il n'a pas été déclaré encore.

Pour DECLAR e une variable, vous devez en spécifier le type, puis son nom.

Ainsi, par exemple, faire ...

int perimeter = width + length; 
return perimeter; 
+0

Ceci est la bonne réponse. –

+0

Merci beaucoup :) – Nimitz