Good afternoon! My problem is this, try to make a for
loop so that I traversed letter by letter a word, and when I did not find it, the counter increased by one and my problem was that when I went through the whole word I increased by one every time the word does not appear ...
Here I leave the piece of code in case I did not understand well ...
primerJugador = jugador1.getText();
comparacion1 = primerJugador.charAt(0);
for (int i=0;i<palabra.length();i++) {
comparacion2 = palabra.charAt(i);
if (comparacion1==comparacion2) {
JOptionPane.showMessageDialog(null, "Letra "+comparacion1 + " encontrada");
encontrado = true;
}
else{
encontrado = false;
}
}
if(encontrado)
{
contador = contador+1;
}
The program runs through all the letters and adds the contador
the times you can not find it.