sorry if my question looks stupid but I'm not really good at For loops. My window looks like this.
When I click on "valider", I want to add every rows in the Prix column to a variable Total. Here is my loop:
float total = 0;
for (int i = 0; i < jTable4.getRowCount(); i++)
total =+ (float) jTable4.getValueAt( i, 2);
When I check what's in my Total variable, it just gives me the content of the last row.
Could you guys help me with this loop ?
Problem is you have used an invalid assignment Operator . =+ should be change as += to get your expected answer .
float total = 0;
for (int i = 0; i < jTable4.getRowCount(); i++) { // Loop through the rows
total += (float) jTable4.getValueAt(i, 2);
}