I have created a program that takes a number from a user, and generates, in the amount entered by user, an array of characters with both upper and lower case letters (but no other characters) which must be in random order. In other words, if user enters 5, program generates 5 random lowercase/upper letters, if user enters 25, program generates 25 letters, etc. etc. My program is almost completely successful, except that I cannot get to a good method to generate ONLY upper-or-lowercase letters. It also generates chars 91-96 ( [, \ ,] , ^, _,' ), and I don't want them.
I tried while and if statements to try to remove undesired chars, as well as within the Math.random formula, replace the 58 with 'desiredChars.length,' which has all desired chars, but nothing seems to work.
// Program to generate random chars.
Scanner sc = new Scanner(System.in);
System.out.println("This program will print an array of random letters based on your specified array size. \nPlease enter your desired array size: ");
int number = sc.nextInt();
char[] arrayList = new char[number];
int i;
int lowercaseCount = 0;
int uppercaseCount = 0;
// final char[] desiredChars = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'};
for (i = 0; i < arrayList.length; i++) {
arrayList[i] = (char) ((65 + Math.random()*(58)));
if (Character.isLowerCase(arrayList[i])) {lowercaseCount++;}
if (Character.isUpperCase(arrayList[i])) {uppercaseCount++;}}
System.out.println("Your array with " + number + " random letter(s) is below:\n"+ Arrays.toString(arrayList));
System.out.println("The number of lowercase in your array is " + lowercaseCount);
System.out.println("The number of lowercase in your array is " + uppercaseCount); }}