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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -