*i changed getNumberofSundays Method. I think it is use ful for you*
public static int getNumberofSundays(String d1,String d2) throws Exception {
//d1 is leave start date d2 is leave end date
// get object in Date form
Date date1=getDate(d1);
Date date2=getDate(d2);
// now get calender objects from it
GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay1(d1));
GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay1(d2));
System.out.println("DAY_OF_MONTH: "
c1.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " c1.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: "
c1.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_MONTH: " c2.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: "
c2.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " c2.get(Calendar.DAY_OF_WEEK));
int noofsun=0;
long leavePeriod = Math.abs(getDiffInDays(date1,date2));
System.out.println("total No of Days"
leavePeriod);
float noOfWeeks=leavePeriod/7;
noofsun=(int)noOfWeeks;
if(c1.get(Calendar.DAY_OF_WEEK)+leavePeriod%7>=7)
noofsun=noofsun+1;
//System.out.print(date2.getDay());
//System.out.println("no of weeks"+noOfWeeks" remainder +remainder"+leavePeriod%7);
//System.out.println("total sun"+noofsun);
return noofsun;
// it should return number of sundays but we type 12 to perform compilation
}