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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -