Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Displays every date in a given year
- */
- import java.util.Scanner;
- class DayCounter{
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a year.");
- int year = scan.nextInt();
- int[] months = {1,2,3,4,5,6,7,8,9,10,11,12};
- for(int i = 0; i < 12; i++){ //loop through each month
- for(int x = 0; x < countDays(months[i], year); x++) //loop through all days in month
- System.out.println(months[i] + "/" + (x+1) + "/" + year);
- }
- }
- static int countDays(int month, int year){
- int count = -1;
- switch (month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- count = 30;
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- count = 30;
- break;
- case 2:
- if (year % 4 ==0)
- count = 29;
- else
- count = 28;
- if ((year % 100 == 0) & (year % 400 != 0))
- count = 28;
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement