Last active
September 29, 2020 12:29
-
-
Save supernovaplus/a309bccd92e6874059dda0abe1b4e943 to your computer and use it in GitHub Desktop.
printBonusDatesBetween
This file contains hidden or 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
import java.text.SimpleDateFormat; | |
import java.util.*; | |
public class Main { | |
static void printBonusDatesBetween(int fromYear, int toYear) { | |
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); | |
Calendar cal = Calendar.getInstance(); | |
cal.set(fromYear, 0, 1); | |
while(Integer.valueOf(cal.get(Calendar.YEAR)) <= toYear) { | |
String[] arrOfStr = format1.format(cal.getTime()).split("-", 3); | |
StringBuilder str = new StringBuilder(); | |
str.append(arrOfStr[0]); | |
str.reverse(); | |
if( String.valueOf(str).equals((String.valueOf(arrOfStr[1]) + String.valueOf(arrOfStr[2]))) ){ | |
System.out.println( format1.format(cal.getTime()) ); | |
} | |
cal.add(Calendar.DATE, 1); | |
} | |
} | |
public static void main(String[] args) { | |
printBonusDatesBetween(2010, 2015); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment