java loops
Collapse
X
-
ok ..i posted print statements to see what was going on. i did a print statement afterand it prints out 0.Code:sum += Integer.parseInt((String)dataTable.getValueAt(i, 4)); System.out.println(sum);
so is the sum+= not working right??Comment
-
actually i just figured it out..i fixed it with the following:
Code:for(int i=0; i < dataTable.getRowCount(); i++) { int entry = Integer.parseInt( (String) dataTable.getValueAt(i,4)); sum += entry; String total = Integer.toString(sum); total1.setText(total);
Thanks for your help!Comment
-
I don't understand why that would help, i.e. the parseInt( ... ) method returns an int that can be directly added to the 'sum' variable, no need for a temporary variable. btw, your indentation stinks. That 'setText( ... )' method shouldn't be in the body of that loop.actually i just figured it out..i fixed it with the following:
Code:for(int i=0; i < dataTable.getRowCount(); i++) { int entry = Integer.parseInt( (String) dataTable.getValueAt(i,4)); sum += entry; String total = Integer.toString(sum); total1.setText(total);
Thanks for your help!
kind regards,
JosComment
Comment