I would like to get explain in creating a random sample password in java using; String passwordChars
Question:
I would like to get explain in creating a random sample password in java using;
- String passwordChars = "..!@#$%^&*()_+-=<>?/,.;:[]{}";
the main method with this string and also creating an array of characters of length 20. the ramdom object which will use to generate index positions to retrieve characters from the passwordChars string. and then using for loop, randomly generate an integer between 0 and passwordChars.length(). that indexing at the length itself is not allowed, to avoid StringIndexOutOfBoundsException Exceptions, as indexing begins at 0. Using the charAt function of the String class, retrieve the character from passwordChars, at the generated index, and store the value thereof into the array for each subsequent position. After termination of the for loop, creating a new String, named password, using the initializer constructor of the String class which takes as a parameter an array of characters. IE String password = new String(characterArray);
- The last thing your program should do is print this String to the console. IE: VG9$Tr^30tCgq4x]&8Qf