Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about this?</p> <pre><code>import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Calendar; import static java.util.Calendar.APRIL; import static java.util.Calendar.AUGUST; import static java.util.Calendar.DECEMBER; import static java.util.Calendar.FEBRUARY; import static java.util.Calendar.JANUARY; import static java.util.Calendar.JULY; import static java.util.Calendar.JUNE; import static java.util.Calendar.MARCH; import static java.util.Calendar.MAY; import static java.util.Calendar.NOVEMBER; import static java.util.Calendar.OCTOBER; import static java.util.Calendar.SEPTEMBER; public class Months { public static void main(String []args) throws IOException { Integer iInput = null; String szInput = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please type either the number of the month, or the month itself to convert."); System.out.print("&gt; "); szInput = br.readLine(); boolean wasInt = false; try { iInput = Integer.valueOf(szInput); System.out.println(numberToMonth(iInput)); wasInt = true; } catch(Exception e) { } if (! wasInt) { szInput = szInput.toLowerCase(); System.out.println(monthToNumber(szInput)); } return; } public static String numberToMonth(int iMonth) { switch(iMonth-1) { case (JANUARY): return "January"; case (FEBRUARY): return "February"; case (MARCH): return "March"; case (APRIL): return "April"; case (MAY): return "May"; case (JUNE): return "June"; case (JULY): return "July"; case (AUGUST): return "August"; case (SEPTEMBER): return "September"; case (OCTOBER): return "October"; case (NOVEMBER): return "November"; case (DECEMBER): return "December"; } return "Unknown"; } public static int monthToNumber(String szMonth) { if (szMonth == null) { return 0; } switch(szMonth.toLowerCase()) { case ("january"): return 1 + JANUARY; case ("february"): return 1 + FEBRUARY; case ("march"): return 1 + MARCH; case ("april"): return 1 + APRIL; case ("may"): return 1 + MAY; case ("june"): return 1 + JUNE; case ("july"): return 1 + JULY; case ("august"): return 1 + AUGUST; case ("september"): return 1 + SEPTEMBER; case ("october"): return 1 + OCTOBER; case ("november"): return 1 + NOVEMBER; case ("december"): return 1 + DECEMBER; } return 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload