# Operations on TableRow object? Can't find sum

**URL:** https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360
**Category:** Coding Questions
**Created:** [April 28, 2024, 7:52pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360 "2024-04-28T19:52:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![syzygy](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@syzygy](https://discourse.processing.org/u/syzygy)
#### Post date: [April 28, 2024, 7:52pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/1 "2024-04-28T19:52:07Z")

</div>

```auto
/*data.csv looks like this- 
                            header
                            1,
                            1,
                            1,
  */                          
Table table;
table = loadTable("data.csv","header");

for(int i = 0; i < table.getRowCount();i++){
   TableRow row = table.getRow(i);
   int a = row.getInt(0);

    println(a);
  }

```

I know that this is a very basic misunderstanding of the data type, but I’ve spent way too long on this problem and I don’t have anyone available to ask. How would you find the sum of (a), all rows in column (0)?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 28, 2024, 8:32pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/2 "2024-04-28T20:32:26Z")

</div>

Declare b before the for loop and say  
b = b+a; in the loop

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [April 28, 2024, 8:44pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/3 "2024-04-28T20:44:55Z")

</div>

Hello @syzygy,

Here is an example with products:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/d/4d8e1c996af32a46512492eea606e91814fc6e03.png)

It will have to be adapted for sum.

Make use of `println()` statements to help understand what your code is doing.

`:)`

---

<div class="post-metadata">

### Author: ![syzygy](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@syzygy](https://discourse.processing.org/u/syzygy)
#### Post date: [April 28, 2024, 9:29pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/4 "2024-04-28T21:29:09Z")

</div>

Thanks, that helps. println(b) returns  
1  
2  
3

I understand that the operation goes something like this:  
1 = (0+1)  
2 = (1+1)  
3 = (2+1)

But what I really need is for the sum to be an int with a value of 3. I feel like the Table class can be really powerful, but there’s something that I’m not conceptually grasping about the data type

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 28, 2024, 9:37pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/5 "2024-04-28T21:37:02Z")

</div>

println gives the correct result only after the for loop

During the for loop it’s going over the rows and adds  
data

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 28, 2024, 9:37pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/6 "2024-04-28T21:37:46Z")

</div>

Not sure what you are getting at

Try with other data in your csv

---

<div class="post-metadata">

### Author: ![syzygy](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@syzygy](https://discourse.processing.org/u/syzygy)
#### Post date: [April 28, 2024, 9:55pm UTC](https://discourse.processing.org/t/operations-on-tablerow-object-cant-find-sum/44360/7 "2024-04-28T21:55:52Z")

</div>

dumb mistake. thanks
