Created
December 3, 2015 10:40
-
-
Save ProZhar/2421aa07723b1e8c83e6 to your computer and use it in GitHub Desktop.
com.javarush.test.level08.lesson11.home09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level08.lesson11.home09; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
/* Работа с датой | |
1. Реализовать метод isDateOdd(String date) так, чтобы он возвращал true, если количество дней с начала года - нечетное число, иначе false | |
2. String date передается в формате MAY 1 2013 | |
Не забудьте учесть первый день года. | |
Пример: | |
JANUARY 1 2000 = true | |
JANUARY 2 2020 = false | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) throws ParseException | |
{ | |
System.out.println(isDateOdd("MAY 15 2014")); | |
System.out.println(isDateOdd("MAY 26 2014")); | |
System.out.println(isDateOdd("MAY 17 2014")); | |
} | |
public static boolean isDateOdd(String date) throws ParseException | |
{ | |
SimpleDateFormat formater = new SimpleDateFormat("MMM d yyyy", Locale.US); | |
Date first = formater.parse(date); | |
Date second = new Date(); | |
long distance = second.getTime() - first.getTime(); | |
int pri = 24 * 60 * 60 * 1000; | |
int dateCount = (int) (distance / pri); | |
return dateCount % 2 == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment