(Java)Why is my array not working as intended? : I have been unable to submit my assignment because of one final discrepancy in my code. I've spent several hours trying to resolve it. My code takes 20 test answers that can either be 'A', 'B', 'C', or 'D', and then tells you whether you passed (>=15 correct) or failed, how many you got right, and how many you got wrong. Afterwards, it tells you the question numbers of the ones you got wrong. However, only the first few numbers are actually recorded to the array I am using, and the last 5 are not (it is always the last 5, regardless of how many you got wrong). What's strange is, I'm using a `for` loop to read the values INTO the array, so there should not be discrepancies. If there was, it would most likely give me an `arrayIndexOutOfBoundsExeption`! Here's the code, there is a comment for the method with the problem (starts at line 81):

    import java.util.Scanner;
    public class ch7 {
    	private static char[] correctAns = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
    	
    	public static void main(String[] args) {
    		Scanner kb = new Scanner(System.in);
    		boolean pass;
    		char[] answers = new char[20];
    		
    		for(int x = 0; x < answers.length; x++) {
    			
    			do {
    				System.out.printf("Enter your answer for question %d:", x + 1);
    				answers[x] = kb.next().charAt(0);
    			}
    			while(answers[x] != 'A' && answers[x] != 'B' && answers[x] != 'C' && answers[x] != 'D' && answers[x] != 'a' && answers[x] != 'b' && answers[x] != 'c' && answers[x] != 'd');
    		}
    		
    		for(int x = 0; x < answers.length; x++) {
    			answers[x] = Character.toUpperCase(answers[x]);
    		}
    		
    		pass = passed(answers);
    		if(pass == true)
    			System.out.println("You Passed!");
    		else
    			System.out.println("You did not pass.");
    		
    		System.out.printf("You got %d answers correct out of 20.\n", totalCorrect(answers));
    		
    		System.out.printf("You answered %d questions incorrectly.\n", totalIncorrect(answers));
    		
    		int[] qMissed = questionsMissed(answers);
    		
    		if(qMissed.length != 0) {
    			System.out.print("You got questions ");
    			for(int x = 0; x < qMissed.length; x++) {
    	
    				if(x == qMissed.length - 1)
    					System.out.printf("and #%d ", qMissed[x]);
    				else
    					System.out.printf("#%d, ", qMissed[x]);
    			}
    			System.out.println("wrong.");
    		}
    	}
    	
    	public static boolean passed(char[] ans) {
    		int correct = 0;
    		int incorrect = 0;
    		for(int x = 0; x < ans.length; x++) {
    			if(ans[x] == correctAns[x]) {
    				correct++;
    			}
    			else
    				incorrect++;
    		}
    		return correct > incorrect ? true: false;
    	}
    	
    	public static int totalCorrect(char[] ans) {
    		int correct = 0;
    		for(int x = 0; x < ans.length; x++) {
    			if(ans[x] == correctAns[x]) {
    				correct++;
    			}
    		}
    			return correct;
    	}
    		
    	public static int totalIncorrect(char[] ans) {
    		int incorrect = 0;
    		for(int x = 0; x < ans.length; x++) {
    			if(ans[x] != correctAns[x]) {
    				incorrect++;
    			}
    		}
    		return incorrect;
    	}
    	
    	public static int[] questionsMissed(char[] ans) { // problem somewhere in this method
    		int nMissed = totalIncorrect(ans);
    		int[] missedQuestions = new int[nMissed];
    		int i = 0;
    		for(int x = 0; x < totalIncorrect(ans); x++) {
    			if(ans[x] != correctAns[x]) {
    					missedQuestions[i] = x + 1;
    					i++;
    			}
    		}
    		return missedQuestions;
    	}
    }