public class Solution {
    public static void main(String[] args) {
        ByteArrayOutputStream password = getPassword();
        System.out.println(password.toString());
    }

    public static ByteArrayOutputStream getPassword() {
        String UpAlphabet = "ABCDEFGHIJKMLNOPQRSTUVWXYZ";
        String Alphabet = "abcdefghijkmlnopqrstuvwxyz";
        String numbers = "0123456789";
        byte[] num =  numbers.getBytes();
        byte[] upAlpha = UpAlphabet.getBytes();
        byte[] alpha = Alphabet.getBytes();

        StringBuilder password = new StringBuilder();

        while (password.length() < 8){
            Random random = new Random();
            switch (random.nextInt(1, 3)){
                case 1:
                    password.append(upAlpha[random.nextInt(25)]);
                    break;
                case 2:
                    password.append(num[random.nextInt(9)]);
                    break;
                case 3:
                    password.append(alpha[random.nextInt(25)]);
            }
        }
        String thePassword = password.toString();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        stream.writeBytes(thePassword.getBytes());
        return stream;
    }
}
Задачка дается с огромным трудом. Незнаю почему. Да и предложенное мною решение не работает.