int [] oddNumbers = {1,3,5,7,9};
oddNumbers[0]=oddNumbers[1];
oddNumbers[1]=oddNumbers[2];
oddNumbers[2]=oddNumbers[3];
oddNumbers[3]=oddNumbers[4];
This would result in : int [] oddNumbers = {3,5,7,9,9} i.e replacing each element in the array( starting at index 0) with the element to its immediate right in the array.
To achieve the result with a for loop I have tried:
for (int i = 0; i <= oddNumbers.length ;i++)
oddNumbers[i] = oddNumbers[i + 1];
I get the following error:
Exception: line 2. java.lang.ArrayIndexOutOfBoundsException
Any thoughts would be gratefully received.