1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
Random r = new Random();
String motPasse = null;
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];
System.out.println(mpLettre);
// ON RECUPERE UN CARACTERE
int indiceCaractere = r.nextInt(tableauCaracteres.length);
System.out.print("-caractere : "+indiceCaractere+" => ");
char mpCaractere = tableauCaracteres[indiceCaractere];
System.out.println(mpCaractere);
} |
Partager