I have to code a program that generates a random password for the user based on the character set they choose from. I did the code to generate the numbers (which I later have to convert to characters), but the code also asks for the password length. How do I code the part where it generates the specific length of the password?
import java.util.Scanner; import java.util.Random; import java.io.*; public class Passwords { public static void main(String[] args) { Scanner in = new Scanner(System.in); String password = ""; int randNum = 0; Random randNumList = new Random(); System.out.println("Password Generation Menu"); System.out.println(); System.out.println("[1] Lowercase Letters"); System.out.println("[2] Lowercase & Uppercase Letters"); System.out.println("[3] Lowercase, Uppercase, & Numbers"); System.out.println("[4] Lowercase, Uppercase, Numbers, & Punctuation"); System.out.println("[5] Quit"); System.out.println(); System.out.print("Enter Selection (1-5): "); int selection = in.nextInt(); if (selection == 1) { while (randNum >= 97 && randNum <= 122) { randNum = randNumList.nextInt(122); } } else if (selection == 2) { while (!(randNum >= 65 && randNum <= 90) && !(randNum >= 97 && randNum >=122)) { randNum = randNumList.nextInt(122); } } else if (selection == 3) { while (!(randNum >= 60 && randNum <= 71) && !(randNum >= 65 && randNum <= 90) && !(randNum >= 97 && randNum >=122)) { randNum = randNumList.nextInt(122); } } else if (selection == 4) { while (randNum >= 48) { randNum = randNumList.nextInt(127); } } else { System.exit(0); } System.out.print("Password Length (1-14): "); int passLength = in.nextInt(); System.out.println("Password: " + password); } }