I have home work due soon and have written most of the code there are only two parts i am having trouble with:

1.Can anyone tell me how to read the even values of an array, add them and then add the amount of even numbers there were in the array????

2.How can i move the values of the arrays around?


thank you in advance for your help, it is greatly appreciated!!! :cheesy:

Your first question is not very clear to me, what I understand is you want to find all even numbers in the array and add them together, plus you wish to keep a track of have many even numbers are in the array

int total = 0;
int evenCount = 0;
for(int i = 0; i < arr.length; i++)
{
     if(arr[i] % 2 == 0)
     {
          total += arr[i];
          evenCount ++;
     }
}

If I mis-understand please explain in more details

To swap value in array is simple just introduce new variable which will temporary store value from one array position

int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;

Thank you so much!

you're the best! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.