java - JTextArea keeps adding lines in for loop, how to prevent this? -


i working on gradebook sort of program. user enters name of student , marks got on 4 tests, 2d array. when click 'student average' button determine average mark of said student, want print student info , average line after. output right now, shown in picture, adds around 15 lines before average displayed.

enter image description here

i'm not sure happening in code causing this, attach actionperformed code of student averages button. code magic happens:

    private void studentaveragesbuttonactionperformed(java.awt.event.actionevent evt) {      int sum = 0;     int studentaverage = 0;      studentname = lastnameinput.gettext() + " " + firstnameinput.gettext();      (int row = 0; row < studentmarks.length; row++) {         (int col = 0; col < studentmarks[0].length; col++) {             if (studentmarks[row][col] != null) {                 studentmarkscreen.settext(studentmarkscreen.gettext() + "   " + string.valueof(studentmarks[row][col]));                 if (studentmarks[row][col].equals(studentname)) {                     if (studentmarks[row][0].length() > 3) {                         (col = 1; col < studentmarks[0].length; col++) {                             sum += integer.parseint(studentmarks[row][col]);                         }                     }                 }             } else {                 continue;             }         }     }     studentaverage = sum / 4;     studentmarkscreen.append("\n");     studentmarkscreen.append("the overall average " + studentname + " " + studentaverage + "%."); 

}

studentname = lastnameinput.gettext() + " " + firstnameinput.gettext(); 

i guess variable lastnameinput.gettext() has garbage.

you can test adding :

system.out.println( "(" + lastnameinput.gettext() + ")" ); 

even if isn't problem need add debug code display value of text area every time set/append text it. can determine statement causing problem.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -