/** MonthAbbreviations.java reads a number from 1-12 and displays * the three-letter abbreviation of the corresponding month. */ 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 keyboard = new Scanner(System.in); int monthNumber = keyboard.nextInt(); // compute the month abbreviation final String MONTH_TABLE = "JanFebMarAprMayJun" + "JulAugSepOctNovDec"; int start = (monthNumber - 1) * 3; int stop = start + 3; String monthAbbrev = MONTH_TABLE.substring(start, stop); // display the month abbreviation System.out.println("\nMonth #" + monthNumber + " begins with '" + monthAbbrev + "'."); } }