public class Main { public static void main(String[] args) { char[] anArray = { '!', '@', '#', '$', '%', '^', '&', '*', '+', '=', '~', '<', '>', '?' }; int passwordLength = 20, symbolCount = 9; while (symbolCount > anArray.length) { symbolCount = (anArray.length - 1); } char[] patternArray = new char[passwordLength]; int srcIndex = 0; for (int j = 0; j < passwordLength; j++) { patternArray[j] = anArray[srcIndex]; srcIndex++; if (srcIndex > (anArray.length - 1)) srcIndex = 0; } System.out.print(patternArray); } }