Question: Write a program that prompts the user for one of the numbers 1, 2, 3, ..., 12 and outputs the corresponding month name January, February,
Write a program that prompts the user for one of the numbers 1, 2, 3, ..., 12 and outputs the corresponding month name January, February, March, ... , December.
Implementation: Create a class with a constructor that takes the number and a method that returns the month string. Make a very long string "January February March ... ", in which you add spaces such that each month name has the same length. Then use substring to extract the month you want. You will need to figure out a little arithmetic to get the correct limits for the substring.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
