Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:11:15+00:00 2026-05-28T15:11:15+00:00

I am trying to create a method that counts the number of each full

  • 0

I am trying to create a method that counts the number of each full months in an array. my array contains the dates in MM/dd/yyyy format. The array can contain dates starting from any date and ending at any date. The dates are in order from oldest to newest and only contain weekdays.

For example, if the array has dates from 6/15/2010 to 1/15/2012, it would return an array of:
jan = 1, feb = 1, mar = 1, apr = 1, may = 1, jun = 1, jul = 2, aug = 2, sep = 2, oct = 2, nov = 2, dec = 2

I was hoping someone could give me some hints, here is what i have so far:

double[] months = new double[12];

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat yyyy = new SimpleDateFormat("yyyy");

for(int ii = 0 ; ii < array.length-length ; ii++){

        date = (Date)formatter.parse(array[ii][0]);
        String currentDateMY = sdf.format(date);
        String currentDateYYYY = yyyy.format(date);

        date = (Date)formatter.parse(array[ii+1][0]);
        String nextDateMY = sdf.format(date);

            if (!currentDateMY.equals(nextDateMY)){

                date = (Date)formatter.parse(array[ii][0]);
                sdf = new SimpleDateFormat("MM");
                String currentDateM = sdf.format(date);

                if (currentDateM.equals("01")) months[0] = jan++;
                if (currentDateM.equals("02")) months[1] = feb++;
                if (currentDateM.equals("03")) months[2] = mar++;
                if (currentDateM.equals("04")) months[3] = apr++;
                if (currentDateM.equals("05")) months[4] = may++;
                if (currentDateM.equals("06")) months[5] = jun++;
                if (currentDateM.equals("07")) months[6] = jul++;
                if (currentDateM.equals("08")) months[7] = aug++;
                if (currentDateM.equals("09")) months[8] = sep++;
                if (currentDateM.equals("10")) months[9] = oct++;
                if (currentDateM.equals("11")) months[10] = nov++;
                if (currentDateM.equals("12")) months[11] = dec++;
            }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:11:15+00:00Added an answer on May 28, 2026 at 3:11 pm

    Brain-dead way of doing it:

    1. Create a GregorianCalendar with the start date and end dates. (put in 1 for the starting day_of_month, and GregorianCalendar.getActualMaximum(DAY_OF_MONTH) for the starting day_of_month for the end date)
    2. Keep adding a month to the start date (GregorianCalendar.add(MONTH, 1)) and check to see if it’s after() the end date. If not, increment that month’s counter.
    3. Add 1 for each the start and end, if the actual start date’s day_of_month component is 1, and if the actual end date’s day_of_month is equal to GregorianCalendar.getActualMaximum(DAY_OF_MONTH).

    If the start day is a Monday, and you want to include the preceding weekend, you can put in checks for that (similarly for the end date being a Friday).

    A smarter way of doing it:

    Get the difference in years between the dates. Increment each month by the difference-2, if indeed it is greater. Then check if the starting month is before or after the ending month, and increment the ones in between accordingly. Check if the starting and ending months themselves are included as above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create a method that take 2 int array as the input
Just trying to create a simple method that counts up 1 on the tally
I am trying to create a method that removes duplicates from a 2d array.
I'm trying to create a method that will sum two timeO objects and return
I am trying to create a method that accepts multiple types of controls -
I am trying to create a generic method that will read an attribute on
I am trying to create a unit test for a method that takes a
I'm trying to create a windowless Ogre application, but it seems that the method
I'm trying to create an application that will let me execute a method specified
I'm trying to create a simple method that receives a ResultSet as a parameter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.