I'm trying to make a method that read from keyboard a,d compare with an enum collection.
The problem is that variable a that contains the match from the comparison I can't return it from the end of the function after the while statement the error is like the variable is not declared.
private static Planet choosePlanet(Scanner scan) {
System.out.println("Voici les planetes Disponible" + Arrays.toString(Planet.values()));
List<Planet> PlanetValues = Arrays.asList(Planet.values());
boolean exist = false;
do {
System.out.println("Choisis une planet");
String choix = scanner.next();
for (int i = 0; i < PlanetValues.size(); i++) {
Planet a = PlanetValues.get(i);
if (a.toString().matches("(?i).*" + choix + ".*") == true) {
exist = true ;
}
return a;
}
} while (exist==false);
return a;
}