Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 12:47 AM
Lange Lange is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 Lange User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 58 sec
Reputation Power: 0
[Homework] month name to 3 letter abbrevation

Hi all,
So i've been struggling with this homework that is convert a month to a 3 letter abbreviation. I i've done many searches that month month numbers to names, abbreviations to months etc, but not what I need.


Here is the number to date from my textbook:

Code:
/** MonthNumbers.java reads a 1-12 number and displays 
 *   the three-letter abbreviation of the corresponding month.
 * 
 * @author Joel Adams, for Alice+Java
 */

import java.util.Scanner;

public class MonthAbbreviations {
  public static void main(String[] args) {
	// get the month number
    System.out.println("To see the first three letters of a month,");
    System.out.print(" enter a month-number (1-12): ");
    Scanner kbd = new Scanner(System.in);		
    int monthNumber = kbd.nextInt();
    // compute the month abbreviation
    final String monthTable = "JanFebMarAprMayJunJulAugSepOctNovDec";
    int start = (monthNumber - 1) * 3;
    int stop = start + 3;
    String monthAbbrev = monthTable.substring(start, stop);
    // display the month abbreviation
    System.out.println("\nMonth #" + monthNumber + 
                        " begins with '" + monthAbbrev + "'.");
  }
}


I'm wondering if name to abbreviation is similar with a few modifications to this? Thanks in advance for any help.

Reply With Quote
  #2  
Old November 9th, 2012, 06:59 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
Please edit your post and wrap the code in code tags.

Look at using an array to hold the month names instead of a String that you have to index into.
Quote:
name to abbreviation

Can you give some examples of that. What are the cases where the abbreviation is not just the first 3 letters?

Reply With Quote
  #3  
Old November 9th, 2012, 08:58 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,814 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 7 h 54 m 5 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
You might consider using a Map.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > [Homework] month name to 3 letter abbrevation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap