getting error message "cannot find symbol – variable radius" java?

getting error message “cannot find symbol – variable radius” java?
here is what i have:

public static void main (String [] args)
{
double value = 0;
double radius;
Scanner keyboard = new Scanner (System.in);

System.out.print(“Enter the radius of the circle: “);
radius = keyboard.nextDouble();
value = Area();
System.out.println(“The area of the circle is ” + value);
}

public static double Area()
{
return Math.PI * Math.pow(2, radius);
}

how can i help it find the variable radius?

Best answer:

In your main() method, you defined a variable called “radius”. This is a local variable, and is not visible outside this method. But you’re trying to use it in your Area() method.

You probably want to pass the radius value to your Area() method as a parameter.

Tags: , , , , , , , ,

Under Forum

1 Comment for getting error message "cannot find symbol – variable radius" java?

  • 1. loltank32147  |  January 21st, 2007 at 9:44 am

    radius is declared inside of the main method and therefore is not accessible by Area(). If you want radius to be seen by all methods, declare radius outside of the methods, as in:

    public class AreaFinder {
    double radius; //radius is declared here so that it can be used by all methods
    public static void main (String [] args)
    {
    double value = 0;
    //radius would not be declared here or else it would only be accessible in method main()
    Scanner keyboard = new Scanner (System.in);

    System.out.print(“Enter the radius of the circle: “);
    radius = keyboard.nextDouble();
    value = Area();
    System.out.println(“The area of the circle is ” + value);
    }

    public static double Area()
    {
    return Math.PI * Math.pow(2, radius);
    }
    }

Leave a Comment for getting error message "cannot find symbol – variable radius" java?

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories