How do i Increment Char Type for a String in Java? -


this works single character want string, have no idea how it.

class test {     public static void main(string arg[])     {         char c = 'a';         c = c + 1;         system.out.println(c);     } } 

suppose string "hello world"
+1 increment return "ifmmp xpsme"

you have split string array of chars , add 1 each char:

public string sumtocharsatstring(string word) {     stringbuffer b = new stringbuffer();     char[] chars = word.tochararray();     (char c : chars) {         if(c != ' ')             c = (char) (c + 1);         b.append(c);     }     return b.tostring();  } 

you dont need use stringbuffer, in order to save memory, practice.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -