jeudi 5 novembre 2020

I'm a beginner at programming and don't understand the problem - SCALA

// Hey guys, it's my first post on programming and I encountered a problem during my //assignment. I have to code in scala a password generator. with the following instructions:

//The user must enter the password’s number of characters (e.g., 8)

//-   The password must consist of at least 8 characters.

// - The password must contain two numerals.

//- The password must contain one special character (e.g., # or @)

// - The remainder of the password must consist of lower- and upper-case // letters.

// The letters, the two numerals and the special character must be chosen // at random. The two numerals and the special character must be inserted // into the password at random.

// And it seems that I can't add the value specChrando to the A value

var numChPass = readLine("Input number of character wanted: ").toInt
if (numChPass < 8) numChPass = 8
val alphabet1 = "qwertzuiopasdfghjklyxcvbnm"
val lowerCh = alphabet1.toCharArray
val higherCh = alphabet1.toUpperCase.toCharArray
val numb = "1234567890".toCharArray
val specialCh = "#@".toCharArray
val numRando = Random.shuffle(numb.toList).take(2)
val specChrando = Random.shuffle(specialCh.toList).head
val A = lowerCh ++ higherCh ++ numRando ++ specChrando
for (x <- 0 to numChPass) print(Random.shuffle(A.toList).head)
print(specChrando)



Aucun commentaire:

Enregistrer un commentaire