Even after multiple attempts, i can't seem to alter my code so both the conditions may apply. I have only been able to satisfy one at a time.
public static String caeserEncrypt(String originalMessage, int shift){
String finalMessage = " ";
int length = originalMessage.length();
for(int i= 0;i<length;i++){
char c = originalMessage.charAt(i);
char shiftedletter = ' ';
if((int)'a'<=(int)c &&(int)c<='z'||(int)'A'<=(int)c &&(int)c<='Z'){
if(shiftedletter>'z' || shiftedletter>'Z'){
shiftedletter = (char)(originalMessage.charAt(i)-(26-shift));
}
else{
shiftedletter = (char)(originalMessage.charAt(i)+shift);
}
}
else{
shiftedletter = originalMessage.charAt(i);
}
finalMessage = finalMessage + shiftedletter;
Aucun commentaire:
Enregistrer un commentaire