Results 1 to 6 of 6
  1. #1
    ezered is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default Need Help for this problem Uppercase.

    Create a program that converts all to uppercase and all to lowercase.

    Enter a String: GOOD BOY
    Last edited by ezered; 12-03-2009 at 01:21 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    What have you done until now and what part of your code made you seek help on this forum?

    kind regards,

    Jos

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    What I'd use is a combination of Character.toLowerCase(ch), Character.toUpperCase(ch), char[] and StringBuilder.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    In case you can't simply use the library functions, you can use a mask to change case, since the off set between upper and lower is a power of two. 0x20 is the correct mask. Use "AND" or "OR" and "negation" as needed. This is assuming the ascii english character set. But that's why it's best to use library functions. Upper case starts at 0x41, lower case at 0x61, IIRC.
    Last edited by rdtindsm; 12-03-2009 at 04:41 PM.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rdtindsm View Post
    In case you can't simply use the library functions, you can use a mask to change case, since the off set between upper and lower is a power of two. 0x20 is the correct mask. Use "AND" or "OR" and "negation" as needed. This is assuming the ascii english character set. But that's why it's best to use library functions. Upper case starts at 0x41, lower case at 0x61, IIRC.
    No need to fiddle with all those magic numbers; the Character class has all you want.

    kind regards,

    Jos

  6. #6
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    The post started out with what was basically an if statement with a clear conditional. Not trying to suggest that it be done differently from using java classes unless that was was the point of the exercise, which was unspecified. I really tried to make that clear.

    At worst, the information might be useful background in other settings. I've had to write these functions in other languages.

Similar Threads

  1. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM
  2. UpperCase problem
    By logieen in forum New To Java
    Replies: 1
    Last Post: 08-03-2008, 11:26 PM
  3. String uppercase/lowercase
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-19-2007, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •