Facebook
From asd, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 107
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. import java.util.Scanner;
  7. /**
  8.  *
  9.  * @author maxim
  10.  */
  11. public class kalendarz {
  12.    
  13.  
  14.  public static void main(String[] strings) {
  15.  Scanner input = new Scanner(System.in);
  16.  System.out.print("Enter a year: ");
  17.  int year = input.nextInt();
  18.  System.out.print("Enter the first day of the year: ");
  19.  int startDay = input.nextInt();
  20.  int numberOfDaysInMonth = 0;
  21.  for (int month = 1; month <= 12; month++)
  22.  {
  23.  System.out.print(" ");
  24.  switch (month)
  25.  {
  26.  case 1:
  27.  System.out.println("January " + year);
  28.  numberOfDaysInMonth = 31;
  29.  break;
  30.  case 2:
  31.  System.out.println("February " + year);
  32.  if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
  33.  numberOfDaysInMonth = 29;
  34.  } else {
  35.  numberOfDaysInMonth = 28;
  36.  }
  37.  break;
  38.  case 3:
  39.  System.out.println("March " + year);
  40.  numberOfDaysInMonth = 31;
  41.  break;
  42.  case 4:
  43.  System.out.println("April " + year);
  44.  numberOfDaysInMonth = 30;
  45.  break;
  46.  case 5:
  47.  System.out.println("May " + year);
  48.  numberOfDaysInMonth = 31;
  49.  break;
  50.  case 6:
  51.  System.out.println("June " + year);
  52.  numberOfDaysInMonth = 30;
  53.  break;
  54.  case 7:
  55.  System.out.println("July " + year);
  56.  numberOfDaysInMonth = 31;
  57.  break;
  58.  case 8:
  59.  System.out.println("August " + year);
  60.  numberOfDaysInMonth = 31;
  61.  break;
  62.  case 9:
  63.  System.out.println("September " + year);
  64.  numberOfDaysInMonth = 30;
  65.  break;
  66.  case 10:
  67.  System.out.println("October " + year);
  68.  numberOfDaysInMonth = 31;
  69.  break;
  70.  case 11:
  71.  System.out.println("November " + year);
  72.  numberOfDaysInMonth = 30;
  73.  break;
  74.  case 12:
  75.  System.out.println("December " + year);
  76.  numberOfDaysInMonth = 31;
  77.  }
  78.  System.out.println("-----------------------------");
  79.  System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
  80.  for (int i = 0; i < startDay; i++) {
  81.  System.out.print(" ");
  82.  }
  83.  for (int i = 1; i <= numberOfDaysInMonth; i++)
  84.  {
  85.  if (i < 10) {
  86.  System.out.print(" " + i);
  87.  } else {
  88.  System.out.print(" " + i);
  89.  }
  90.  if ((i + startDay) % 7 == 0) {
  91.  System.out.println();
  92.  }
  93.  }
  94.  System.out.println("");
  95.  startDay = (startDay + numberOfDaysInMonth) % 7;
  96.  }
  97.  }
  98. }
  99.  
  100.