Untitled
unknown
plain_text
6 months ago
1.1 kB
6
Indexable
public class ConvertMonthN2Str { public static void main(String[] args) { // Check if there is exactly one command-line argument if (args.length != 1) { System.out.println("Please provide a month number as an argument."); return; } // Try to parse the argument as an integer try { int monthNumber = Integer.parseInt(args[0]); // Array of month names String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // Check if the month number is valid if (monthNumber >= 1 && monthNumber <= 12) { System.out.println(months[monthNumber - 1]); // Print the corresponding month } else { System.out.println(monthNumber + " is not a valid month"); } } catch (NumberFormatException e) { System.out.println(args[0] + " is not a valid month"); } } }
Editor is loading...
Leave a Comment