
April 25th, 2003, 08:16 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Dates missing?
I am taking a beginning java class and I did a search on the web for calendar projects and I found this one. This code is suppose to print out a calendar for a month and year that's input by a user. The code prints out the month and array of days of the week but it will not print out the dates of the month.
Would someone be able to tell be why the program scrolls down after the days of the week row instead of printing out the dates 1, 2, 3, etc.? How do I get the dates of the month to show up.
Thank you for your patience and assistance.
PHP Code:
public class Calendar
{
public static void main(String[] args)
{
int year = 0;
//Determine if it is a leap year
boolean isLeapYear = true;
if (isLeapYear)
year=year+1;
int total=0;
int startDay;
int month;
//array for number of days in each month
int DaysEachMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
//array for corresponding days
String NameofMonth[]={"January","February","March","April","May",
"June","July","August","September","October",
"November","December"};
//ask user to enter year
System.out.println("Enter a full year:");
year = SavitchIn.readLineInt();
if(year<1800)
System.out.println("Year out of range!");
System.exit(0);
//ask user to enter month
System.out.println("Enter a month in a form of a "
+ "number between 1-12:");
month = SavitchIn.readLineInt();
if(isLeapYear==true)
DaysEachMonth[1]=29;
//Get the total days from 1800 to year -1
for (int i=1800;i<year;i++)
{
if(isLeapYear==true)
total=total+366;
else
total=total+365;
}
//Add days from Jan to the month prior to the
//calendar month
for (int i=1;i<month;i++)
total=total+DaysEachMonth[(i-1)];
startDay=(total+3)%7;
//Print the month title, i.e. May, 1999
System.out.println(" "+(month)+","+year);
System.out.println("----------------------------");
System.out.println("Sun Mon Tue Wed Thur Fri Sat");
//Determine if it is a leap year
if ((year % 400 == 0)||((year % 4 == 0)&&(year % 100 != 0)))
//Print month body
//Pad space before the first day of the month
for (int i=0; i<startDay;i++)
{
System.out.println("");
}
for(int i=1;i<=DaysEachMonth[month-1];i++)
{
if ((i + startDay) % 7 == 0)
System.out.println();
System.out.println();
}
}
}
|