For a class assignment I have to write a method that called encodeChars that takes an array of characters and shifts each lowercase letter in the array up by one. The method is supposed to modify the array passed in and has no return value. My existing code is as follows:
public void encodeChars(char[] change){
for (int x = 0; 0 < change.length; x++){
switch (change[x]){
case('a'):
change[x] = 'b';
break;
case('b'):
change[x] = 'c';
break;
case('c'):
change[x] = 'd';
break;
case('d'):
change[x] = 'e';
break;
case('e'):
change[x] = 'f';
break;
case('f'):
change[x] = 'g';
break;
case('g'):
change[x] = 'h';
break;
case('h'):
change[x] = 'i';
break;
case('i'):
change[x] = 'j';
break;
case('j'):
change[x] = 'k';
break;
case('k'):
change[x] = 'l';
break;
case('l'):
change[x] = 'm';
break;
case('m'):
change[x] = 'n';
break;
case('n'):
change[x] = 'o';
break;
case('o'):
change[x] = 'p';
break;
case('p'):
change[x] = 'q';
break;
case('q'):
change[x] = 'r';
break;
case('r'):
change[x] = 's';
break;
case('s'):
change[x] = 't';
break;
case('t'):
change[x] = 'u';
break;
case('u'):
change[x] = 'v';
break;
case('v'):
change[x] = 'w';
break;
case('w'):
change[x] = 'x';
break;
case('x'):
change[x] = 'y';
break;
case('y'):
change[x] = 'z';
break;
case('z'):
change[x] = 'a';
break;
default:
change[x] = change[x];
break;
}
}
}
While I know that the switch is probably overkill for changing the incoming chars and a loop would be more efficient, my issues comes in when trying to test the code in my main method.
For the life of me I can not figure out, or find anywhere in class notes/ on the internet of how to get this method to take in an array of chars and modify it.
This goes along with testing the method, to make sure I correctly wrote the code to do as I need it. Also, sorry for the any issues that may have resulted in my inexperience of posting code to stackoverflow.