Bonjour a tous
je dois faire un jeu de pendu mais je suis conicée dans l'affichage de mon mot.


j'ai un mot a deviner : motcherche
motEtoile : elle a evidement meme taille q motCherche et elle contien que ******* et je construit mon mot a trouve petit a petit ..
mon probleme qd je compare mon mot par rapport a ma lettre saisi , il affiche un erreur ?? taille du mot pourtant j'ai insiste dans la declaration d'avoir la meme taille

bref ?? un idee pour m'aider ca sera gentil et merci ..

PS : je dois aussi penser qd il y a une espace ds mon mot a deviner ( un mot composé !! ) ..
une condition



import java.util.Random;

import java.util.Scanner;

public class Run {



public static void main(String[] args) {
// TODO Auto-generated method stub

String[] tab = { "un mot", "un autre mot", "Bonjour" };
int ind = new Random().nextInt(tab.length);
String motCherche= tab[ind]; // mot choisi en hazar
String[] motCache = new String[motCherche.length()]; // mot a construit a meme taille que mot a deviner
int iteration = motCherche.length() ; // nbre iteration possible selon le mot et le niveau du jeu

System.out.println("Bienvenue dans le pendu vous pouvez choisir le niveau de jeu !");

System.out.println("1- facile ");

System.out.println("2- Moyen ");

System.out.println("3- Dificile ");

Scanner sc = new Scanner(System.in);
int choixNiveau = sc.nextInt();

switch( choixNiveau)
{
case 1 : { iteration = motCherche.length()+ 5 ;}
case 2 : { iteration = motCherche.length()+ 2 ;}
case 3 : { iteration = motCherche.length() ;}

}
System.out.println("Vous avez choisi ce niveau avec " + iteration +" essais pour trover votre mot !! ");

// aficher le mot qu on va deviner sous forme etoile !!
String [] motEtoile = new String[motCherche.length()];
String espace = " ";
for ( int i =0 ; i < motCherche.length(); i++)
{
if (motCherche.charAt(i) == ' ')
{ motEtoile[i] = "" + espace ;}
else if ( motCherche.charAt(i) >= 'a' && motCherche.charAt(i) <= 'z')
{ motEtoile[i] = " * " ; }

System.out.print(motEtoile[i]);

}
System.out.println();
// cherche caratere et affiche ce qu'il passe !!
do {
for ( int i =0 ; i < motCherche.length(); i++)
{
System.out.println(" Veuillez entrer votre lettre ");
char lettre = sc.nextLine().charAt(0);
if (lettre == motCherche.charAt(i))
{ System.out.println(" Bingo !! une bonne lettre ");

motEtoile[i] = ""+lettre ;
iteration = iteration ;
}
else { System.out.println(" Oups !! une mauvaise lettre ");


iteration = iteration -1 ;
}


System.out.print(motEtoile[i]);
}

}while(iteration>0);



}
}