Calendar

Printing a calendar

Page 1 of 1

1 Replies - 1256 Views - Last Post: 19 October 2008 - 02:23 PM

#1 javaishard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-October 08

Calendar

Posted 19 October 2008 - 12:13 PM

I need this program to print out the correct start day for each month. Can anyone please help?
public class MyCalendar
{

	int days[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	String months[] = { "","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };

	int startDay[] = { 0, 3,6,7,3,5,1, 3,6,2,4,7,2 };   

	public static void main(String[] a) 
	{
	MyCalendar c = MyCalendar();	

	}
	
	public MyCalendar() 
	{
		for(int m = 1; m <= 12; m++) 
		{
			printMonth(m,days[m],2008,startDay[m]);	

		}
	}
	public void printMonth(int month, int daysInMonth, int year, int startDay) 
	{
		System.out.printf("%20s", months[month] + " " + year + "\n");
		System.out.printf("%4s%4s%4s%4s%4s%4s%4s", "Su","Mo", "Tu", "We","Th","Fr","Sa\n");
		System.out.printf("%4s%4s%4s%4d%4d%4d%4d", "","", "",1,2,3,4);					
											
		for(int i = 5; i <= days[month];i++)
		{
								if(i==5||i==12||i==19||i==26)
		System.out.println();
		System.out.printf("%4d", i);
		 if(i==days[month])
		{
		System.out.println();
		System.out.println();
	}
}
	}
}	

This post has been edited by javaishard: 19 October 2008 - 12:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Calendar

#2 GWatt   User is offline

  • member icon

Reputation: 309
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: Calendar

Posted 19 October 2008 - 02:23 PM

you probably should've posted this in the java forum. Someone will probably come along and move it for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1