0

$ I write a code to count how many sundays in a given month. But it does not work, can anyone help me, please repair it. Thanks.

import java.util.Calendar;

public class Sundays {

    int count;
    public int getSundays(int month,int year) 
    { 

    Calendar calendar=Calendar.getInstance(); 
    calendar.set(year, month-1,1); 
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
    int dayofWeek = calendar.get(Calendar.DAY_OF_WEEK);
    for(int day =1;day <=daysInMonth;day++) {
    calendar.set(year, month-1,1); 

    if(dayofWeek==0); 
    {count++ ; 
    }
    }

    return count;
}       
    public static void main(String[] args) 
    { 

    Sundays d= new Sundays(); 
    int e= d.getSundays(2,2015);
    System.out.println(e);

    } 
}
  • 1
    read this http://stackoverflow.com/questions/9909361/how-can-i-find-saturdays-and-sundays-in-a-given-month – Michele Lacorte Sep 10 '15 at 15:17
  • You use neither or your two parameters, month or year. The number of Sundays depends on the particular month you have. – djna Sep 10 '15 at 15:23
  • what do you mean? my method received two parameters to return number of sundays in a given month. I have read some answer above, but not fix to my problem. Can you help me Javanis.? – Long Phandinh Sep 10 '15 at 15:39

0 Answers0