Hi Guys!
This is my first post and i am a complete newbie to Java...
I am trying to total and print the number of apples in each basket. But when i print it prints each transaction at each point in the array, causing a double up in my print information. Did that make sense? Please see below.
this is my code so far...
int size = 10;
int arrayOneValue;
int arrayTwoValue;
int count;
int maxBasketNumber;
int appleCount;
maxBasketNumber = 0;
for (arrayOneValue=0; arrayOneValue < size; arrayOneValue = arrayOneValue +1)
{
if(BasketNumber[arrayOneValue] > maxBasketNumber)
maxBasketNumber = BasketNumber[arrayOneValue];
}
appleCount = 0;
for (arrayOneValue=0; arrayOneValue < size; arrayOneValue = arrayOneValue +1)
{
count = 0;
for(arrayTwoValue = 0; arrayTwoValue < size; arrayTwoValue++)
{
if(BasketNumber[arrayOneValue] == BasketNumber[arrayTwoValue])
count++;
}
System.out.println("BasketNumber: " + BasketNumber[arrayOneValue] + " Total of apples: " + count);
System.out.println("");
appleCount++;
}
System.out.println("");
This is the output:
BasketNumber: 1 Total of apples: 3 // I would like to print each BasketNumber only once with its value not repeat the same info
BasketNumber: 1 Total of apples: 3
BasketNumber: 3 Total of apples: 3
BasketNumber: 0 Total of apples: 2
BasketNumber: 3 Total of apples: 3
BasketNumber: 2 Total of apples: 1
BasketNumber: 0 Total of apples: 2
BasketNumber: 4 Total of apples: 1
BasketNumber: 1 Total of apples: 3
BasketNumber: 3 Total of apples: 3
Any help would be greatly appreciated!