Question: I would like to get explain in creating a random sample password in java using; String passwordChars = ..!@#$%^&*()_+-= ?/,.;:[]{}; the main method with this

I would like to get explain in creating a random sample password in java using;

  1. 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);

  1. The last thing your program should do is print this String to the console. IE: VG9$Tr^30tCgq4x]&8Qf

Step by Step Solution

3.28 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Lets break down the steps to create a random sample password using the provided instructio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!