Skip to content

Instantly share code, notes, and snippets.

@bholzer
Created February 12, 2012 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bholzer/1811143 to your computer and use it in GitHub Desktop.
Save bholzer/1811143 to your computer and use it in GitHub Desktop.
import java.util.Random;
import java.util.Scanner;
public class Easy4 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("How long would you like your password to be?");
int length = in.nextInt();
String list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$&1234567890";
StringBuilder password = new StringBuilder(length);
Random indexPicker = new Random();
for (int i = 0; i < length; i++) {
password.append(list.charAt(indexPicker.nextInt(list.length())));
}
System.out.println(password);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment