0

This is a the part of my code that java says where the error is.String.valueOf(Answer[i].toUpperCase().charAt(j)); I can't figure out why. can anyone please help?

   for (int i=0; i<=Answer.length; i++)
    {
        int IEAs=0, IEBs=0, IEdashes=0;
        int SIAs=0, SIBs=0, SIdashes=0;
        int TFAs=0, TFBs=0, TFdashes=0;
        int JPAs=0, JPBs=0, JPdashes=0;

        for (int k=0; k<70; k=k+7)
        {

            for (int j=k,p=0; j<=k+6; j++,p++)
                {
                        SevenAnswers[p] = 
         String.valueOf(Answer[i].toUpperCase().charAt(j));

                }
            switch (SevenAnswers[0].charAt(0))
            {
            case 'A':
                IEAs +=1;...
  • 1
    try changing the outer loop from i<=Answer.length to i – JDSchenck Feb 13 '18 at 03:18
  • It could be `j` variable, you should check it and make sure that `0 <= j < answer[i].touppercase().length()`. Also, you should check your `p` variable. And one more thing, you should seperate your code to many parts, so it's easier to debug ex: `Answer answer = Answer[i]; String answerAsString = answer.toUpperCase(); and some checking and String sevenAnswer = answerAsString.charAt(j); and then SevenAnswers[p]=sevenAnswer` it's longer than the original but you can figure out where problem is. Edit: The outer loop should be ` for (int i=0; i – No Em Feb 13 '18 at 03:27
  • why did you give k as 70 and j as k+6. Might be an issue from there? – Jayanth Feb 13 '18 at 03:31
  • Thank you all! I have implemented your feedback, and it seems to be working. – gedion simegnew Feb 13 '18 at 03:37
  • @Jayanth this is the instruction. (why i set K to 70 and j to increase by 6: – gedion simegnew Feb 13 '18 at 03:39
  • ... if we consider the I/E to be dimension 1, the S/N to be dimension 2, the T/F to be dimension 3, and the J/P to be dimension 4, the map of questions and an examinee’s answers to their respective dimensions would look like this: 1223344122334412233441223344122334412233441223344122334412233441223344 BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA Your program will process a test data file. The file will contain line pairs, one per examinee. The first line has the examinee’s name, and the second has the examinee's 70 answers (all "A", "B" or "-"). – gedion simegnew Feb 13 '18 at 03:41
  • example, Betty BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA Ben aabaabbabbbaaaabaaaabaaaaababbbaabaaaabaabbbbabaaaabaabaaaaaabbaaaaabb Han BA-ABABBB-bbbaababaaaabbaaabbaaabbabABBAAABABBAAABABAAAABBABAAABBABAAB "A" and "B" in the file can be upper or lowercase. A dash represents a question that was skipped. – gedion simegnew Feb 13 '18 at 03:41
  • first line of code should be 'for (int i=0; i – janith1024 Feb 13 '18 at 05:06

0 Answers0