+ 2

Error "cannot find symbol: variable area"

Have anybody help me 😭how can i solve this problem public static double circleArea (double r){ if (r>=0){ double area = Math.PI *Math.pow(r , 2.0); } return area; } cannot find symbol: variable area return area; ^

15th Apr 2021, 3:29 AM
PEIYIN CHEAH
PEIYIN CHEAH - avatar
3 Respuestas
+ 2
Try this: public static double circleArea (double r){ double area = 0; if (r>=0){ area = Math.PI *Math.pow(r , 2.0); } return area; } or this: public static double circleArea (double r){ if (r>=0){ return Math.PI *Math.pow(r , 2.0); } return 0; } Your area variable has scope within the {} brackets which is why you have a problem compiling the return area; which is after the closing }.
15th Apr 2021, 4:27 AM
Josh Greig
Josh Greig - avatar
0
Oh~ I got it, thank you so much 😆
15th Apr 2021, 4:39 AM
PEIYIN CHEAH
PEIYIN CHEAH - avatar
0
What was the parameter you gave?
15th Apr 2021, 4:40 AM
Akshat Surana
Akshat Surana - avatar