import java.util.Calendar;
import java.io.*;
public class DayOfYear {
public static void main (String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);
System.out.print("Enter the date (yyyy,mm,dd): ");
String date = in.readLine();
Calendar cal = Calendar.getInstance();
String[] seperate = date.split(",");
int year = Integer.parseInt(seperate[0]);
int month = Integer.parseInt(seperate[1])-1;
int day = Integer.parseInt(seperate[2]);
if(year < 1 || month < 0 || month > 12 || day < 0 || day > 31){
System.out.println("The date is invalid");
}else{
try{
cal.set(year, month, day);
}catch(Exception e){
System.out.println("The format is invalid");
}
int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
System.out.println ("Day of Year :" + dayOfYear);
}
}
}
I keep getting the error Java.lang.indexoutofboundsexception:1
on line 16.
I dont know what I've done wrong with this....can someone please tell me what I've done wrong?