You get arrayIndexOutofBoundsException: 1
on this line:
if (argarray[j] == keys[j])
because your argarray
there has always only one element, and j
takes values from 0...args.length
.
Also, you don't need an inner loop at all, you could simplify your program like this:
public static void main(String args[]) {
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
int correctCount = 0;
for (int i = 0; i < args.length && i < keys.length; i++) {
if (args[i].charAt(0) == keys[i]) {
correctCount++;
}
}
System.out.println("Your correct count is " + correctCount);
}