I have used collections here. HashMap . But still its failing.
package com.codegym.task.task08.task0828;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
/*
Month number
*/
public class Solution {
Map<String, Integer> months = new HashMap<String, Integer>();
public void getMonth(){
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
months.put("January",1);
months.put("February",2);
months.put("March",3);
months.put("April",4);
months.put("May",5);
months.put("June",6);
months.put("July",7);
months.put("August",8);
months.put("September",9);
months.put("October",10);
months.put("November",11);
months.put("December",12);
try {
String input = bufferedReader.readLine();
for (Map.Entry<String, Integer> m : months.entrySet()){
if (m.getKey().equals(input))
System.out.println(input + " is month " +m.getValue());
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
//write your code here
Solution solution = new Solution();
solution.getMonth();
}
}