Question: The following code shifts all characters in a character array one place to the right, and moves the last character to the front: public static
The following code shifts all characters in a character array one place to the right, and moves the last character to the front:
public static void shift ( char [] str) { int len = str.length; //Assume string is not empty char last = str[len- 1]; for ( int i = len - 1; i > 0; i--) { str[i] = str[i- 1]; } str[ 0] = last; } Completely rewrite the code so that it shifts all characters one place to the left, and moves the first character to the end of the character array. You can assume the string contains at least one character.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
