INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

What Methond to use?

What Methond to use?

(OP)
I am trying to output the suffix for streets. and avenue numbers But not sure what method to use to extract the first string. I need to use a switch statement for each of the cases below. What do you recommend I use for the following:

•Numbers with a 1 in the tens place (for example: 11, 14, 216) should have a 'th' suffix
•All other numbers ending in 1 should have a 'st' suffix
•All other numbers ending in 2 should have a 'nd' suffix
•All other numbers ending in 3 should have a 'rd' suffix
•All other Numbers should have a 'th' suffix

thank you.
 

RE: What Methond to use?

I'd try and keep it fairly readable rather than try some convoluted piece of logic that looks funky:

CODE

        int units = num % 10;
        int tens = num % 100 - units;
        
        if(tens == 10) {
            System.out.println(num+"th");
        } else {
            switch(units) {
            case 1:
                System.out.println(num+"st");
                break;
            case 2:
                System.out.println(num+"nd");
                break;
            case 3:
                System.out.println(num+"rd");
                break;
            default:
                System.out.println(num+"th");
            }
        }

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close