i am trying to write a loop that counts how many times the number 3 appears in a one-dimensional array called array.
is this correct?Code:
int count = 0;
for (int x = 0; x < Array.length; x++)
if (Array[x] == 3)
count++;
Printable View
i am trying to write a loop that counts how many times the number 3 appears in a one-dimensional array called array.
is this correct?Code:
int count = 0;
for (int x = 0; x < Array.length; x++)
if (Array[x] == 3)
count++;
Looks ok to me.
Also,
Why not try the code instead of coming here to see if it is ok. It is ok to test code :D
No. ....Maybe. It depends on what Array really is, I can't tell from what you posted. If your array is actually a class, that would depend on whether or not there is a member called length. If it's just an array of ints or something
might work better.PHP Code:
x < sizeof Array / sizeof *Array
thanks, also i do check the code but sometimes i have noticed that you can get the code to work but it might not be the proper way to write it. so what i am trying to do is make sure that i am writing it properly to make it work.
thanks again