import java.util.*;
class Friday
{
public static void main(String a[])
{
int nthWeek =2, monthsBehind=1;
int weekDay=6; //Sunday=1, Monday=2, ...Friday=6, Saturday=7
System.out.println(getNthWeekDay(monthsBehind, nthWeek,weekDay));
}
static Date getNthWeekDay(int monthsBehind, int nthWeek, int weekDay)
{
GregorianCalendar xMonth=new GregorianCalendar();
//point calendar to n months behind
xMonth.add(Calendar.MONTH,-(monthsBehind));
//select the second week of the month
xMonth.set(Calendar.WEEK_OF_MONTH,nthWeek);
//select the required day of the week
xMonth.set(Calendar.DAY_OF_WEEK,weekDay);
return xMonth.getTime();
}
}