Results 1 to 4 of 4
  1. #1
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default How to count no of sundays in month

    Hi all,
    Please can anyone of you provide me code for counting no of sundays in a month, if month and year is specified.

    Thanks in advance...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please can anyone of you provide me code for...
    um, no, that's not how it works here as this is not a "provide me with the code service".

    You must provide the code, at least a good faith attempt, then we can help you learn what is necessary to improve on it.

  3. #3
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    how much sundays are there in a month?
    - those of your total amount of days.

    or you could try this
    Java Code:
    if (day==saterday) {
    // do blablbalabla
    }
    
    if (day==sunday) {
    //do nothing
    }
    i think that's how you could do something like that, but i'm not really experienced with Java.
    This can help you out a little, but i'm not giving you an entire code.

  4. #4
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Thumbs up Sovled..

    Thanks all for replies.....
    I created the solution using calendar class.....
    I did it..

    For all you guys this is the code..


    Java Code:
     
    
    import java.util.Calendar; 
      
    public class Sundays 
    { 
        public static void main(String[] args) 
        {     
            
            Sundays d= new Sundays(); 
            System.out.println("Sundays in month "+d.getSundays(2009,11)); 
    
            }         
            public int getSundays(int month,int year) 
            { 
            int count=0; 
            Calendar calendar=Calendar.getInstance(); 
            calendar.set(year, month,1); 
            int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
    
            for(int i=1;i<=days;i++) 
            { 
            
                    calendar.set(year, month, i); 
                    int day=calendar.get(Calendar.DAY_OF_WEEK); 
                    if(day==1) 
                    count++        ; 
            
            } 
                    return count; 
            } 
    }
    Thanks again guys....

Similar Threads

  1. Month and year program code!!!!HELP PLEASE!!!
    By chitwood in forum New To Java
    Replies: 4
    Last Post: 10-13-2010, 01:21 PM
  2. Replies: 0
    Last Post: 08-06-2008, 05:02 PM
  3. Current month
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:40 AM
  4. Replies: 0
    Last Post: 01-04-2008, 09:32 AM
  5. date one month back
    By senzacionale in forum New To Java
    Replies: 1
    Last Post: 12-24-2007, 09:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •