Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Calendar
- {
- public static void main(String [] args)
- {
- System.out.println(" Sun Mon Tue Wed Thu Fri Sat ");
- headers();
- cal(31, 6);
- headers();
- }
- public static void headers()
- {
- System.out.println("+------+------+------+------+------+------+------+");
- }
- public static String padded(int n, int width)
- {
- String s= "" + n;
- for (int i = s.length(); i < width; i++)
- {
- s = " " + s;
- }
- return s;
- }
- public static void cal(int days, int sun)
- {
- int printdays = 1;
- int weekday = 1;
- while(printdays <= days)
- {
- if (weekday == (8 - sun) % 7 + 1 && printdays == 1)
- {
- System.out.print("|" + padded(printdays, 6));
- printdays++;
- }
- else if(weekday < (8 - sun) % 7 + 1 && printdays == 1)
- {
- System.out.print("| ");
- }
- else if(printdays > 1)
- {
- System.out.print("|" + padded(printdays, 6));
- printdays++;
- }
- weekday++;
- if(weekday > 7)
- {
- System.out.println("|");
- weekday = 1;
- }
- }
- if(weekday != 1)
- {
- for(; weekday <= 7; weekday++)
- {
- System.out.print("| ");
- }
- System.out.println("|");
- }
- }
- }
Add Comment
Please, Sign In to add comment