java - Printing a Calendar from Given Month/Year -
I am working on a Java assignment and after specifying the user's month and one year it includes a calendar printing is. I can not use calendar or Gregorian calendar classes My problem is that the calendar does not print correctly on a Saturday with its first day. I've seen my code for about an hour, and I'm not sure what I'm doing is using Zeiler's uniformity to find the first day of the month, which is indicated by "H". For example, the calendar looks like this in March 2008 (incorrectly):
March 2008 su mo to v f f sa 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
This is my code:
package calendar; Import java.util.Scanner; Public Class Calendar {Private Static Ent Counts = 0; Private Static In H = 0; Public stable boolean leap (int year) {if ((year% 4 == 0) & amp; (year% 100 == 0)) (year% 400 == 0)) {true; } Other {return false; }} Public static zero firstDayOfYear (int year) {int month = 13; year--; H = (1 + (int (((Month + 1) * 26) / 10.0) + year + (int) (year / 4.0) + 6 * (int) (year / 100.0) + (int) (year / 400.0))% 7; String dayname = ""; Switch (H) {Case 0: dayName = "Saturday"; break; Case 1: Name of the Day = "Sunday"; break; Case 2: dayName = "Monday"; break; Case 3: Day Group = "Tuesday"; break; Case 4: Day Group = "Wednesday"; break; Case 5: Day Group = "Thursday"; break; Default: dayName = "Friday"; break; } System.out.println ("First day of the year" + dayName); } Public static void before DAO month (int month, int year) {if (months == 1 = months == 2) {month + = 12; year--; } H = (1 + (int) (((Month + 1) * 26) / 10.0) + Year + (Int) (Year / 4.0) + 6 * (Int) (Year / 100.0) + (Int) (Year) / 400.0))% 7; String dayname = ""; Switch (H) {Case 0: dayName = "Saturday"; break; Case 1: Name of the Day = "Sunday"; break; Case 2: dayName = "Monday"; break; Case 3: Day Group = "Tuesday"; break; Case 4: Day Group = "Wednesday"; break; Case 5: Day Group = "Thursday"; break; Default: dayName = "Friday"; break; } System.out.println ("The first day of the month" + dayName); } Public static in zero zero days (int month, int year) {int [day] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; If (months == 2 & amp; amp; amp; leap (year)) day [months] = 29; Numdays = Day [month]; System.out.println ("Number of days in the month" + numdays); } Public static zero printCal {int [month], "July", "June", "May", "June", "July", "String [] MonthNum = {" "," January "," February "," March "," April " August September October November December"}; System.out.println ("+ month name [month] +" "+ year); System.out.println (" su mo to vu fa saas "); for (int i = 0; i & lt; H - 1; i ++) for System.out.print (""); (int i = 1; i
There will be a similar problem for your code. This means that the problem is probably in this line -
for (int i = 0; i & lt; h -1, i ++) system. Out.print (""); Due to being h
due to
it will fix it for you instead of 7 k. You can either fix this or you will need to start from 0 to 6 instead of h
for 1 to 7 and make other necessary changes of the course.
Comments
Post a Comment