Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with loop / equals ==
    primarykey
    data
    text
    <p>I have the following bit of code that I am having some difficulty with. My expectation for output should be the applicant # with their correlated test score. The first position of both arrays is for the answer key. Not quite sure where I am going wrong with this, but any help would be appreciated.</p> <pre><code>public class applicantCheck { //* main method public static void main(String[] args) { int i = 0, j = 0, correct; //* initialization of applicant id's and answers int[] appID = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; char[][] appAnswers = { {'N','Y','N','N','Y','N','N','Y','N','Y'}, {'N','Y','Y','N','Y','N','Y','Y','N','Y'}, {'N','Y','N','Y','N','Y','Y','Y','N','N'}, {'N','Y','Y','N','Y','Y','Y','Y','Y','Y'}, {'Y','Y','N','N','Y','N','N','Y','Y','Y'}, {'Y','Y','N','Y','Y','Y','N','N','T','N'}, {'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'}, {'N','Y','N','N','N','Y','N','Y','N','Y'}, {'Y','N','Y','N','Y','N','Y','N','Y','N'}, {'Y','Y','Y','N','N','Y','Y','N','Y','N'}, {'N','N','N','N','N','N','N','N','N','N'}, {'Y','N','Y','Y','N','Y','Y','N','Y','N'}, {'N','Y','N','N','Y','Y','N','N','N','Y'}, {'N','Y','N','Y','N','Y','N','Y','N','Y'}, {'Y','N','Y','N','Y','Y','N','Y','N','Y'} }; System.out.println("Applicant #\t\tMark (out of " + appAnswers[i].length + ")"); for (i = 1; i &lt; appID.length; i++) { System.out.printf("%-9d", appID[i]); correct = 0; for (j = 0; j &lt;= i; j++) { if (appAnswers[0][j] == appAnswers[i][j]) { correct++; } } System.out.printf("%10d\n", correct); } // end of for loop System.out.println(); } // end of main } // end of file </code></pre> <p>The output is:</p> <pre><code>--------------------Configuration: &lt;Default&gt;-------------------- Applicant # Mark (out of 10) 1 2 2 3 3 3 4 4 5 3 6 2 7 6 8 3 9 2 10 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at applicantCheck.main(applicantCheck.java:36) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload