# Assume you are given an int variable named nPositive and a 2-dimensional array of ints that has been created and assigned to a2d. Write some statements that compute the number of all the elements in the entire 2-dimensional array that are greater than zero and assign the value to nPositive.

8

### CHALLENGE:

Assume you are given an int variable named nPositive and a 2-dimensional array of ints that has been created and assigned to a2d. Write some statements that compute the number of all the elements in the entire 2-dimensional array that are greater than zero and assign the value to nPositive.

### SOLUTION:

```nPositive = 0;
for (int i=0; i&lt;a2d.length; i++)
for (int j=0; j&lt;a2d[i].length; j++)
if (a2d[i][j] &gt; 0)
nPositive++;
```

• AL says:

nPositive = 0;
for (int i=0; i< a2d.length; i++){
for (int j=0; j 0)
nPositive++;
}
}

• AlanW says:

nPositive = 0;
for (int i = 0; i < a2d.length; i++)
{
for (int j = 0; j 0)
{
nPositive++;
}
}
}

• AlanWo says:

nPositive = 0;
for (int i = 0; i < a2d.length; i++)
{
for (int j = 0; j 0)
{
nPositive++;
}
}
}

• AlanWo says:

nPositive = 0;
for (int i = 0; i < a2d.length; i++)
{
for (int j = 0; j 0)
{
nPositive++;
}
}
}

• AlanWon says:

nPositive = 0;
for (int i = 0; i < a2d.length; i++)
{
for (int j = 0; j 0)
{
nPositive++;
}
}
}

• hotrodjeremy says:

nPositive = 0;
for (int i = 0; i < a2d.length; i++)
for (int j = 0; j 0)
nPositive++;

• j p says:

try this one:

nPositive = 0;
for (int i=0; i<a2d.length; i++){
for (int j=0; j 0){
nPositive++;
}
}
}

• shusma kafle says:

nPositive = 0;
for (int i=0; i<a2d.length; i++){
for (int j=0; j 0){
nPositive++;
}
}
}