Any help for array question
Hello to All:
I want to tally or count some of the elements that I have in array but not sure how.
I have for example: int myArray[] = {90,93,80,81,71,72,73,74};
My objective is to tally all of the 90's, tally all of the 80's and tally all of the 70's.
So, the result that I want to have would look something like the following:
System.out.println ("The total tally number of 90's is " 2 );
System.out.println ("The total tally number of 80's is " 2 );
System.out.println ("The total tally number of 70's is " 4 );
I do not want to add these numbers, just want to count them.
Also I want to use a "forloop" :confused: to achieve the result intead of just declaring it at 2 or 4 etc..
Any help Thankyou
[799 byte] By [
Recency] at [2007-11-11 8:29:32]

# 1 Re: Any help for array question
int nine = 0;
int eight = 0;
int seven = 0;
for (loop through elements)
element = array element at this index
if (element < 100)
if (element >= 90) nine++;
else if (element >= 80) eight++;
else if (element >= 70) seven++;
There's other ways of doing it, but this should be the easiest for you to understand
# 2 Re: Any help for array question
int nine = 0;
int eight = 0;
int seven = 0;
for (loop through elements)
element = array element at this index
if (element < 100)
if (element >= 90) nine++;
else if (element >= 80) eight++;
else if (element >= 70) seven++;
There's other ways of doing it, but this should be the easiest for you to understand
I was able to achieve and include many other objectives such as adding and dividing in one single forloop with this counting analogy.
ThankYou for the help and tutor :WAVE: