"Khanh Le" <le*******@earthlink.net> wrote in message news:<2f*****************@newsread2.news.pas.earth link.net>...
Would someone shows me the java syntax to create a 2D array of a calendar,
where the rows represents months, such as: Jan, Feb... and columns represent
days; assuming that there are 29 days in Feb? I don't know whether to
declare this 2D array in String or int, since the months are string while
days are int. Thanks
I don't think an array is the best approach. You could read about the
class java.util.Calendar at
http://java.sun.com/j2se/1.4.2/docs/api/
That will let you compute that 29 is the last day of Calendar.FEBRUARY
in 2004, 31 is the last day of Calendar.MARCH in 2003, etc.
To look up an array of int's, starting from a String, you could use a
Hashtable. This is awkward, so I don't recommend it, but I'll show it
to you.
import java.util.Hashtable;
Hashtable h = new Hashtable();
int[] daysJan = new int[31];
for (int i = 0; i < 31; ++i) {
daysJan[i] = i+1;
}
h.put("January", daysJan);
// Do the same for the other months.
// Later...
String nameOfMonth = "January";
int[] daysOfMonth = (int[])h.get(nameOfMonth);
// daysOfMonth is now the int array {1,2,...,31}