Code :
char [] tableauChiffres = {'0','1','2','3','4','5','6','7','8','9'}; //int [] tableauChiffres = {0,1,2,3,4,5,6,7,8,9}; char [] tableauLettres = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char [] tableauCaracteres = {'@','-','#','_','!'}; char [] constructionMP = new char [6]; char mpChiffre = ' '; for (int i = 0; i < 2; i++){ // ON RECUPERE UN CHIFFRE // sélectionne au hasard un indice dans le tableau int indiceChiffre = r.nextInt(tableauChiffres.length); System. out. print("-chiffre : "+indiceChiffre+ " => " ); // retourne le nombre correspondant à cette indice mpChiffre = tableauChiffres[indiceChiffre]; System. out. println(mpChiffre ); // ON RECUPER UNE LETTRE int indiceLettre = r.nextInt(tableauLettres.length); System. out. print("-lettre : "+indiceLettre+ " => " ); char mpLettre = tableauLettres[indiceLettre]; // ON RECUPERE UN CARACTERE int indiceCaractere = r.nextInt(tableauCaracteres.length); System. out. print("-caractere : "+indiceCaractere+ " => " ); char mpCaractere = tableauCaracteres[indiceCaractere]; System. out. println(mpCaractere ); }
|