I'm just a starter at java, and I'm trying to figure out the codingbat "Ceaser Cipher" problem. The questions says to "Develop a method that accepts as input a shift value and a message. The shift value will be no less than -25 and no greater than 25. Any character that occurs in the message and that is not an upper case letter should be encoded as itself." The program already applies the message and value. For example, if the message is "ABCDE" and the shift is 1, it should print "BCDEF".
Eveyrtime I try to run my code, I get a "char cannot be converted to java.lang.String line:9" error. Does anyone know how to fix this?
public String CaesarCipher(int shift, String message) {
for (int i = 0;i < message.length(); i++){
char letter = message.charAt(i);
if (Character.isUpperCase(letter)){
int ascii = (int)letter;
ascii += shift;
char newMsg = (char)ascii;
return newMsg;
}
else{
return letter;
}
}
}