This is what I have so far, but when I run it, I get a Java mismatch error.
This is my array:
char[] letters = {'A', 'B' , 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
/********************************************************************************
shiftRight() will move the contents of the array one slot to the right
********************************************************************************/
public static void shiftRight( char [] letters )
{
char last = letters[letters.length-1]; // save off first element
// shift right
for( int index =letters.length-1; index >= 0 ; index-- )
letters[index+1] = letters [index];
// wrap last element into first slot
letters[0] = last;
System.out.print("\nshifted Array: " );
}
You can do something like:
I only modified your:
letters.length-1intoletters.length-2and printed the array.Another, easier approach is to use,
System.arraycopylike:To print the array you can also use: