java - Reversing string and toggle lower-upper-case -


i need write application takes string input. after processing, should print out string reversed, , characters switched lower uppercase , vise versa. want achieve using stringbuilder.

sample run:
input: hello human
output: namuh olleh

here straight forward , simple way of solving problem:

  1. read user input using instance scanner class. , nextline() method. (construct scanner giving system.in argument.)

  2. create stringbuilder.

  3. fetch array of characters input string, using instance input.tochararray()

  4. reverse array arrays.aslist , collections.reverse

    collections.reverse(arrays.aslist(yourchararray)); 
  5. loop through list using instance for-each loop.

    for (character c : yourchararray) {     ... } 
  6. for each character, check if c.isuppercase (if append c.tolowercase()) else append c.touppercase().

(an alternative approach give stringbuilder input-string argument, , manipulate string in-place using reverse, charat , setcharat methods.)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -