Question : What will the year, month and day be?

I am trying to get this printed out but I am not sure how to do it properly. The dates will change from time to time.

How can I do this?

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
*************************************************************************************
Dec 2010
*************************************************************************************
Mon Tue Wen Thu Fri Sat Sun
01 02 03 04 05
06 07 08 09 10 11 12
13 14 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
*************************************************************************************

Answer : What will the year, month and day be?

You should be able to adapt something like:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
/*
    ID:
    Name: Parry Gill
    Date: February 21, 2010

    Description: Display Calender
*/
import java.util.*;


public class Four29 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("Enter year: ");

        int yr = in.nextInt();

        System.out.print(
            "\nEnter first day, between 0 to 6, 0 for Sunday and so on..: ");

        int day = in.nextInt();

        for (int m = 1; m <= 12; m++) {
            String monthN = "";
            int numD = 0;

            switch (m) {
                case 1:
                    monthN = "January ";
                    numD = 31;

                    break;

                case 2:
                    monthN = "February ";

                    if ((((yr % 4) == 0) && ((yr % 100) != 0)) ||
                            ((yr % 400) == 0)) {
                        numD = 29;
                    } else {
                        numD = 28;
                    }

                    break;

                case 3:
                    monthN = "March ";
                    numD = 31;

                    break;

                case 4:
                    monthN = "April ";
                    numD = 30;

                    break;

                case 5:
                    monthN = "May ";
                    numD = 31;

                    break;

                case 6:
                    monthN = "June ";
                    numD = 30;

                    break;

                case 7:
                    monthN = "July ";
                    numD = 31;

                    break;

                case 8:
                    monthN = "August ";
                    numD = 31;

                    break;

                case 9:
                    monthN = "September ";
                    numD = 30;

                    break;

                case 10:
                    monthN = "October ";
                    numD = 31;

                    break;

                case 11:
                    monthN = "November ";
                    numD = 30;

                    break;

                case 12:
                    monthN = "December ";
                    numD = 31;

                    break;
            }

            System.out.println("\n             " + monthN + yr);
            System.out.println("_______________________________________");
            System.out.println("Sun   Mon   Tue   Wed   Thu   Fri   Sat");

            for (int sp = 1; sp <= day; sp++)
                System.out.print("      ");

            for (int p = 1; p <= numD; p++) {
                if (((day % 7) == 0) && (day != 0)) {
                    System.out.println();
                }

                System.out.printf("%3d   ", p);
                day += 1;
            }

            day %= 7;

            System.out.print("\n\n");
        }
    } // end of main method
} // end of class
Random Solutions  
 
programming4us programming4us