My code:
import java.util.Scanner;
public class MonthMapper{
static String month;
static int month_num;
public static boolean isMonthNumber (String str) {
month = str;
month_num = Integer.parseInt(month);
return (month_num >= 0 && month_num < 12);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter Month: ");
month = sc.next();
System.out.println (isMonthNumber (Integer.toString(month_num)));
}
}
I have to write a static class method boolean isMonthNumber(String str)
that takes a String as an input and returns boolean value. The method returns True
if the input string represents an integer value between 1 and 12, otherwise the method returns should return False
.
Currently for some reason my program always returns true even when i enter a value greater than 12.