I'm doing a class exercise about reserved java keywords, and I want to change the color in the input of a scanner. Happy to hear any suggestion!
Here's my code if you want to take a look.
while (repetir || contador == max) {
String palabras = new Scanner(System.in).nextLine().toLowerCase();
if (palabras.contains(".")) {
System.out.println("Has acertado las siguientes palabras: "
+ acertadas);
repetir = false;
} else {
if(reservadas.contains(palabras)) {
palabras = bien + palabras; //This is my attempt to switch the color
acertadas.add(palabras);
contador++;
} else {
System.out.println(mal + "No es correcto" + ANSI_RESET);
}
if (contador == 50) {
System.out.println("ENHORABUENA!!!");
System.out.println("Has acertado todas las palabras "
+ "reservadas");
repetir = false;
}
}
}
When I press the intro keyword and the word writed in the scanner is correct, I want to switch the color to green.