Advertisement
horselurrver

DayCounter

Sep 14th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. /**
  2.  * Displays every date in a given year
  3.  */
  4. import java.util.Scanner;
  5. class DayCounter{
  6.     public static void main(String[] args){  
  7.         Scanner scan = new Scanner(System.in);
  8.         System.out.println("Enter a year.");
  9.         int year = scan.nextInt();
  10.         int[] months = {1,2,3,4,5,6,7,8,9,10,11,12};
  11.         for(int i = 0; i < 12; i++){ //loop through each month
  12.             for(int x = 0; x < countDays(months[i], year); x++) //loop through all days in month
  13.                 System.out.println(months[i] + "/" + (x+1) + "/" + year);
  14.         }
  15.     }
  16.         static int countDays(int month, int year){
  17.             int count = -1;
  18.             switch (month) {
  19.                 case 1:
  20.                 case 3:
  21.                 case 5:
  22.                 case 7:
  23.                 case 8:
  24.                 case 10:
  25.                 case 12:
  26.                     count = 30;
  27.                     break;
  28.                 case 4:
  29.                 case 6:
  30.                 case 9:
  31.                 case 11:
  32.                     count = 30;
  33.                     break;
  34.                 case 2:
  35.                     if (year % 4 ==0)
  36.                         count = 29;
  37.                     else
  38.                         count = 28;
  39.                     if ((year % 100 == 0) & (year % 400 != 0))
  40.                         count = 28;
  41.             }
  42.             return count;
  43.            
  44.         }
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement