Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.text.*;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Scanner;
- public class CountWorkingDays {
- public static void main(String[] args){
- Scanner s = new Scanner(System.in);
- DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
- Date[] holidays = {
- new Date(2000, 1, 1),
- new Date(2000, 3, 3),
- new Date(2000, 5, 1),
- new Date(2000, 5, 6),
- new Date(2000, 5,24),
- new Date(2000, 9, 6),
- new Date(2000, 9, 22),
- new Date(2000, 10, 1),
- new Date(2000, 12, 24),
- new Date(2000, 12, 25),
- new Date(2000, 12, 26)
- };
- try {
- Date startDate = format.parse(s.nextLine());
- Date endDate = format.parse(s.nextLine());
- Calendar start = Calendar.getInstance();
- start.setTime(startDate);
- Calendar end = Calendar.getInstance();
- end.setTime(endDate);
- int cntr = 0;
- for (Date i = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), i = start.getTime()){
- Calendar c = Calendar.getInstance();
- c.setTime(i);
- int currentDay = c.get(Calendar.DAY_OF_WEEK);
- Date currentDate = new Date(2000, i.getMonth(), i.getDate());
- if(!Arrays.asList(holidays).contains(currentDate) && (currentDay != 6 && currentDay != 7)){
- cntr++;
- }
- }
- System.out.println(cntr);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement