public static void main(String[] args) {
String message, encryptedMessage = "";
int key;
char ch;
Scanner sc = new Scanner(System.in);
key = sc.nextInt();
message = sc.nextLine();
sc.useDelimiter(" ");
// I think the problem is in the encrypting formula.
for(int i = 0; i < message.length(); ++i){
ch = message.charAt(i);
if(ch >= 'a' && ch <= 'z'){
ch = (char)(ch + key);
if(ch > 'z'){
ch = (char)(ch - 'z' + 'a' - 1);
}
encryptedMessage += ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = (char)(ch + key);
if(ch > 'Z'){
ch = (char)(ch - 'Z' + 'A' - 1);
}
encryptedMessage += ch;
}
else {
encryptedMessage += ch;
}
}
while(sc.hasNext()){
System.out.println(sc.next()+encryptedMessage);
}
sc.close();
}
This is my code and I use delimiter for the text. The input I use doesn't get encrypted. I don't understand what the problem is. Can somebody help me with the code?