DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2008

    Problem filling an array..

    Hi Guys,

    First time posting here..

    First off this is a college assignment and i'm not looking for a quick fix here just some direction.

    I have to take a year (int) from user and then print out the calendar for that year. Months: 3 Across 4 Down.

    I am trying to fill a 12[8] 2D Array 1 2D Element for each month.

    It should look like: < array element >
    JANUARY ------------ <0>
    Mo Tu We Th Fr Sa Su <1>
    1 2 3 4 5 6 <2>
    7 8 9 10 11 12 13 <3>
    14 15 16 17 18 19 20 <4>
    21 22 23 24 25 26 27 <5>
    28 29 30 31 <6>
    --filled with spaces--- <7>

    My problem is filling elements elements 2 to 7. If on the first week the first day is different each month how can I tell what the first day of the second week is going to be?

    I have tried many things and it frying my head because it is a really early problem and can't go any further if I can't fix this.

    Any ideas? Oh yeah i'm not really looking for code on how to do this..just logical advice..



  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    How are you storing/determining the historical data (what day of the week Jan 1 is for the given year)? That determines which element holds "1" in row 2.

    the first element in row 3 is one more than the last element in row 2.

    Have you seen those "perpetual calendars"? If you want the calendar for 1985, look at calendar #x, which is the same as 1993 and 2007? This is the perfect kind of data for a lookup table(s) and stored data setup, which is stored in files and loaded into memory upon request (if this was a production kind of program).

  3. #3
    Join Date
    Mar 2008
    I will be using a function to determine what day of the week Jan 1 is.

    How would I go about a routine that would check the last date of the previous row and add one for the beginning of the next row??

  4. #4
    Join Date
    Dec 2004
    San Bernardino County, California
    To get the value for row 3, column 0, you would query row 2 column 6, determine the value held there, add 1, insert the value as a string(?), keep count

    OR - just have a dayOfTheMonth variable that is incremented as soon as it is assigned to a location in your 2D array, then when you go to your new location (let's say, Sunday/Monday of your next week) you would just read the value of dayOfTheMonth and insert that value at the new location, then increment dayOfTheMonth and read that into the next location, etc., continuing while dayOfTheMonth is less than or equal to the daysInTheMonth value for the given month which you've read from a table.

Similar Threads

  1. having problem with array of arrays
    By zaacze in forum Java
    Replies: 12
    Last Post: 04-01-2007, 06:32 PM
  2. Replies: 3
    Last Post: 03-31-2007, 04:11 PM
  3. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 04:40 AM
  4. Changing Array Length Problem
    By Damo in forum ASP.NET
    Replies: 3
    Last Post: 10-15-2002, 02:58 PM
  5. Calling Stored Procedures of Oracle PL/SQL
    By Narayan in forum VB Classic
    Replies: 6
    Last Post: 06-20-2001, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.