简体   繁体   中英

How can I add content of different rows of my jTable in a variable?

sorry if my question looks stupid but I'm not really good at For loops. My window looks like this.

jFrame

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);  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM