I’m writing a method that checks an array for how many odd numbers it contains. The idea is I use a for loop to test if a number is odd, and if it is, it then raises the variable b by one, and then it returns b as the number of odds. I wrote it like this:
for ( int a = 0, b = 0; values[a]%2==1;a++){
b++;
}
return b;
but it gives me an error “return b;
^
b cannot be resolved”.
What am I doing wrong?
You don’t need a
bvalue to do need to check for the end of the array. What you have similar towhat you may have intended is to count the number of odd values which would look like this.
or