I'm currently doing a program where I have to encrypt a string typed in by the user. I can randomise the letters and let a = c (randomly generated letter) etc... but the one thing I can't seem to do is if there's a space in the string given by the user. So if the user types in "Encrypt this string" , I will be given an error. How can I put the space character in my array so I can change it when it is entered?
char [] arrayAlphabet;
arrayAlphabet = new char [26];
for (int i=0; i<26; i++)
{
arrayAlphabet[i] = (char)('a' + i);
}
public static char [] createCipher(char [] arrayAlphabet, char [] cipherAlphabet)
{
List<Character> chars = new ArrayList<>(26);
for (char c = 'a'; c <= 'z'; c++)
{
chars.add(c);
}
Collections.shuffle(chars);
for (int i = 0; i<26; i++)
{
cipherAlphabet[i] = chars.get(i);
}
return cipherAlphabet;
Thank you, any help is appreciated.