Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Dictionary;
- import java.util.Hashtable;
- import java.util.Scanner;
- public class Rechnik_Homework {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Dictionary<String, Integer>MyDictionary = new Hashtable();
- MyDictionary.put("January", 1);
- MyDictionary.put("February", 2);
- MyDictionary.put("March", 3);
- MyDictionary.put("April", 4);
- MyDictionary.put("May", 5);
- MyDictionary.put("June", 6);
- MyDictionary.put("July", 7);
- MyDictionary.put("August", 8);
- MyDictionary.put("September", 9);
- MyDictionary.put("October", 10);
- MyDictionary.put("November", 11);
- MyDictionary.put("December", 12);
- for (int i = 0; i < 2; i++) { //Repeat max 2 times
- System.out.println("Choose month: ");
- String month = scan.nextLine();
- System.out.println("Month number: " + MyDictionary.get(month));
- }
- System.out.println("---------------------------------------");
- Dictionary<Integer, String>MyDictionary2 = new Hashtable();
- MyDictionary2.put(1, "January");
- MyDictionary2.put(2, "February");
- MyDictionary2.put(3, "March");
- MyDictionary2.put(4, "April");
- MyDictionary2.put(5, "May");
- MyDictionary2.put(6, "June");
- MyDictionary2.put(7, "July");
- MyDictionary2.put(8, "August");
- MyDictionary2.put(9, "September");
- MyDictionary2.put(10, "October");
- MyDictionary2.put(11, "November");
- MyDictionary2.put(12, "December");
- for (int i = 0; i < 2; i++) { //Repeat max 2 times
- System.out.println("Choose month number: ");
- int number = scan.nextInt();
- if (number < 1 || number > 12) {
- System.out.println("Wrong month number!");
- } else {
- System.out.println("Month: " + MyDictionary2.get(number));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement