Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Farahim Ibrahimli
- *
- * Question 2
- */
- import java.util.Scanner;
- public class Q2 {
- private static int printCalendar(String title, int startingDay, int numDays) {
- System.out.println(title);
- System.out.println("Su Mo Tu We Th Fr Sa");
- int column = 0;
- for (int i = 0; i < startingDay; i++) {
- System.out.printf("%2s ", " ");
- column++;
- }
- for (int day = 1; day <= numDays; day++) {
- if (column % 7 == 0) {
- System.out.println();
- }
- System.out.printf("%2d ", day);
- column++;
- }
- System.out.println();
- return column % 7;
- }
- public static void main(String[] args) {
- int[] daysInMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- Scanner in = new Scanner(System.in);
- System.out.print("Enter the year: ");
- int year = in.nextInt();
- if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
- daysInMonths[1] = 29;
- }
- System.out.print("What day January start (0-Sun,1-Mon,2-Tue,3-Wed,4-Thu,5-Fri,6-Sat): ");
- int day = in.nextInt();
- for (int i = 0; i < months.length; i++) {
- day = printCalendar(months[i] + " " + year, day, daysInMonths[i]);
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement