//################################################################ // // PasswordGenerator.java // // Here Are Two Sample Run: // // Your password is: [R2-D2] // Your password is: [C3-P0] // //################################################################ import java.util.Random; public class PasswordGenerator { public static void main (String[] args) { Random rand = new Random(); // Get the two letters (1st and 4-th caracters) int firstChar = rand.nextInt(26); // 0 to 25 int fourthChar = rand.nextInt(26); // 0 to 25 // Get the two numbers (2nd and 5-th caracters) int secondChar = rand.nextInt(10); // 0 to 9 int fifthChar = rand.nextInt(10); // 0 to 9 // Print the password System.out.print("Your password is: ["); System.out.printf("%c", 'A'+firstChar); System.out.print(secondChar); System.out.print("-"); System.out.printf("%c", 'A'+fourthChar); System.out.print(fifthChar); System.out.print("]\n"); } }