I\'m working on a Java assignment and it involves printing a calendar after the user specifies a month and a year. I cannot use the Calendar or GregorianCalendar classes. My pro
The problem is that your indexes are messed up. What that means is that you are starting your months and days of the weak from 1 instead of 0. However here
h = (1 + (int)(((month + 1) * 26) / 10.0) + year + (int)(year / 4.0) + 6 * (int)(year / 100.0) + (int)(year / 400.0)) % 7
the %7 at the end makes it start at 0! This causes the loop
for (int i = 0; i < h - 1; i++)
System.out.print(" ");
to be
for (int i = 0; i < -1; i++)
System.out.print(" ");
since h is 0 for Saturday.
To fix this issue, you should start all indexes in your functions with 0. Then when you get user input indexed at 1, simply subtract 1 and pass it into your functions. Then you also won't have that blank entry in front of all your arrays (which by the way should be static finals at the top of the class).