Advertisement
Guest User

DR Challenge #4 Easy

a guest
Jul 19th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package challenges;
  2.  
  3. import java.util.Scanner;
  4.  
  5. class Four {
  6.     Integer mult;
  7.     Integer length;
  8.    
  9.     public static void main(String[] args) {
  10.         Four scramble = new Four();
  11.         scramble.prompt();
  12.         scramble.generate();
  13.     }
  14.    
  15.     public void prompt() {
  16.         System.out.println("How many passwords would you like to generate?");
  17.         Scanner user_input = new Scanner(System.in);
  18.         mult = user_input.nextInt();
  19.        
  20.         System.out.println("How many characters per password?");
  21.         length = user_input.nextInt();
  22.         user_input.close();
  23.     }
  24.    
  25.     public void generate() {
  26.         char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  27.         StringBuilder encrypted = new StringBuilder();
  28.         int j = 0;
  29.         while (j < mult) {
  30.             for (int i = 0; i < length; i++) {
  31.                 encrypted.append(alphabet[(int)(Math.random()*26)]);
  32.                 //System.out.println(encrypted);
  33.                 //System.out.println(alphabet[(int)(Math.random()*26)]);
  34.             }
  35.             System.out.println(encrypted);
  36.             encrypted.delete(0, encrypted.length()-1);
  37.             j++;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement