Here’s the relevant code:
public static String[] runTeams (String CPUcolor)
{
boolean z = false ;
//String[] a = new String[6] ;
boolean CPU = false ;
while (z == false)
{
while (CPU==false)
{
String[] a = assignTeams () ;
printOrder (a) ;
for (int i = 1; i<a.length; i++)
{
if (a[i].equals(CPUcolor)) CPU = true ;
}
if (CPU==false)
{
System.out.println ("ERROR YOU NEED TO INCLUDE THE COLOR OF THE CPU IN THE TURN ORDER") ;
}
}
System.out.println ("is this turn order correct? (Y/N)") ;
String s = getIns () ;
while (!((s.equals ("y")) || (s.equals ("Y")) || (s.equals ("n")) || (s.equals ("N"))))
{
System.out.println ("try again") ;
s = getIns () ;
}
if (s.equals ("y") || s.equals ("Y") )
z = true ;
}
return a ;
}
the error i get is:
Risk.java:416: cannot find symbol
symbol : variable a
location: class Risk
return a ;
^
Why did i get this error? It seems that a is clearly defined in the line String[] a = assignTeams () ; and if anything is used by the lineprintOrder (a) ;` it seems to me that if the symbol a really couldn’t be found then the compiler should blow up there and not at the return statment.
(also the method assignTeams returns an array of Strings.)
The variable
ais defined within the scope of thewhile (CPU==false)loop — it’s not accessible outside of that while loop’s scope. You need to defineainside the outermost scope (the same scope that the return statement is in). You can either keep the assignment where it is, or if it’s possible, do it at the same time as definition.