I re coded it with different names for my array and it worked, but when I cross check the two, I can't spot the error..
Code:
java.lang.ArrayIndexOutOfBoundsException: 25
at A3Q2.main(A3Q2.java:67)[/I]
Can you guys please help me? I tried everything.
The program is supposed to code an input of a word into an array
Code:
class A3Q2
{
public static void main (String[] args)
{
char original[]; // Original Alphabet
original = new char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
char code[]; // Code corresponding to Alphabet
code = new char [] {'t','m','e','s','f','k','j','a','x','n','o','v','u','l','c','h','z','g','y','b','w','p','d','r','i','q'};
int n = 0;
char [] wa = new char[n];
int C;
int I;
int C2;
int I2;
int p;
// READ IN GIVENS - use the class ITI1120
System.out.println(" Please input a word");
wa = ITI1120.readCharLine();
n = wa.length;
char [] wa2 = new char[n];
char [] wa3 = new char[n];
// BODY
C = 0;
C2 = 0;
{
while (C < n)
{
I = 0;
while ( I <= 25)
{
if ( wa[C] == original[I])
{
wa2[C] = code[I];
}
I = I + 1;
}
C = C + 1;
}
}
p =0;
while (p < n)
{
System.out.println ( wa2[p] );
p = p+1;
}
}
}