I am getting the error Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 26 in my code when i try to run certain letters (e) and i dont know how to resolve it.
The array contains 26 characters(each letter of the alphabet). Can anybody see the problem in the code?
//Breaking up the letters from the input and placing them in an array
char[] plaintext = input.toCharArray();
//For loops that will match length of input against alphabet and move the letter 14 spaces
for(int i = 0;i<plaintext.length;i++) {
for(int j = 0 ; j<25;j++) {
if(j<=12 && plaintext[i]==alphabet[j]) {
plaintext[i] = alphabet[j+14];
break;
}
//Else if the input letter is near the end of the alphabet then reset back to the start of the alphabet
else if(plaintext[i] == alphabet[j]) {
plaintext[i] = alphabet [j-26];
}
}
}