java - Problems with loop / equals == -
i have following bit of code having difficulty with. expectation output should applicant # correlated test score. first position of both arrays answer key. not quite sure going wrong this, appreciated.
public class applicantcheck { //* main method public static void main(string[] args) { int = 0, j = 0, correct; //* initialization of applicant id's , 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 + ")"); (i = 1; < appid.length; i++) { system.out.printf("%-9d", appid[i]); correct = 0; (j = 0; j <= i; j++) { if (appanswers[0][j] == appanswers[i][j]) { correct++; } } system.out.printf("%10d\n", correct); } // end of loop system.out.println(); } // end of main } // end of file
the output is:
--------------------configuration: <default>-------------------- 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 @ applicantcheck.main(applicantcheck.java:36)
don't want solve problem since homework, here's hint.
array indexes go 0 number of elements -1. check loop make sure doesn't go past end.
Comments
Post a Comment