java - How to store a space in a char array? -


i'm writing caesar cypher program can't figure out how store space in char array. here encrypt method

public static string encrypt(string msg, int shift)  {     char[] list = msg.tochararray();     (int = 0; < list.length; i++) {         // shift letter         char letter = list[i];         letter = (char) (letter + shift);         if (letter > 'z') {             letter = (char) (letter - 26);         }         else if (letter < 'a') {             letter = (char) (letter + 26);         }         else if (letter == ' ') {             letter = '\0';         }         list[i] = letter;     }     // return final string.     return new string(list); } 

literally, answer question is:

    list[i] = ' '; 

however, code written looks rather broken. hint: think about:

  • what happens characters aren't letters in range a z (lower case!), and

  • what happens letter before test - if (letter == ' ') { ....


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -