#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Write a class that takes a string of text from the user and reverses the capitalizati


    For instance, if I input the string “Mary had a little lamb.” the results would be
    “.BMAL ELTTIL A DAH YRAm”!

    In JAVA.

    I don't like to bother people with specific questions but I can't seem to find an answer for this question online.
    If anyone would help they'd have my thanks.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    What have you tried?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by NormR
    What have you tried?
    I'm a complete noob. Somethings in Java I can do and other things I can't. Or more like I have questions memorized that I know and if it's not one of those questions than it's like the Great Wall of China.
    This question is just the last one in my packet and like I said I haven't been able to piece it together. So, again, if anyone can help me they have my thanks, big time.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Start with making a list of the steps the program could do to solve the problem. Then take the steps one at a time and try to write the code for it. If you have problems, post the code and ask some questions about the problems you are having.

    There looks like there are two parts to the job:
    1) reverse the String
    2) invert the case of the characters

    Pick one of those and work out the steps the code needs to do.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0
    Have I got something here?

    public static String reverseAndCapitalize(final String input) {
    final char[] charsInput = input.toCharArray();
    final char[] charsOutput = new char[charsInput.length];
    for (int i = 0; i < charsInput.length; i++) {
    final char c = charsInput[i];
    final char output = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
    charsOutput[charsInput.length - i - 1] = c;
    }
    return new String(charsOutput);
    }
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Does it compile, execute and do what you want?

    Please wrap the code in code tags:
    [code]
    THE CODE HERE
    [/CODE]

IMN logo majestic logo threadwatch logo seochat tools logo