I want to take year and month from the user one per line and I have to print the day of week for the corresponding year and month with day as 28 for all inputs, i printed the day_of_week for the first input and for second input an exception is thrown by jvm can anyone help me??
For example the inputs are:
- 1999-5
- 2000-7
The console should be able to display the:
- june28th of 1999
- august 28th of 2000.
The month starts from 0 to 11(0-11)
import java.util.Calendar;
public class Calendar1 {
public static void main(String[] args) {
int day = 0;
String[] input = new String[2];
int[] year = new int[1];
int[] month = new int[1];
String[] split = new String[2];
Calendar cal = Calendar.getInstance();
System.out.println("Enter The Year And Month(YYYY-M): ");
Scanner s = new Scanner(System.in);
for(int i=0;i<2;i++) {
input[i] = s.nextLine();
}
for(int i=0;i<2;i++) {
split = input[i].split("-");
year[i] = Integer.parseInt(split[0]);
month[i] = Integer.parseInt(split[1]);
cal.set(year[i],month[i],28);
day[i] = cal.get(Calendar.DAY_OF_WEEK);
System.out.println(day[i]);
}
}
}