Looking at the screenshot, radicand
is unavailable in Main because it's not "Global" like you think it is, but is instead a local variable. If you wanted radicand
to be a global, it should be declared public static
in a class somewhere (which is the closest thing to Global in Java), you'll need to refer to it as NameOfClassRadicandIsIn.radicand
.
That said, Java is a language built specifically for a programming style that considers globals to be evil (and not without good reason, problems with globals are just awful things to debug). Fortunately, your code doesn't even need that variable, because you can cut out the middle man with:
double radical = rootradicand(handleradicand(a,b,c));
Though if you do want to keep the variable, simply declaring it in your Main
method would work:
double radicand = handleradicand(a,b,c));
double radical = rootradicand(radicand);
Note that I added radical
because the line after your call to rootradicand(...)
has the exact same problem.
As you learn the language if you do find yourself tempted to try using a global (i.e. public static
in java, this should be considered a last resort. You seem to be writing programs that only have one class now, but when you're dealing with multiple classes, any variables you want to expose between them should be declared as private
and accessed with getter and setter methods.