I'm quite new to programming, and I was trying to find the next nearest palindromic date that will occur and I wrote the following code. But the problem that I'm facing is that it keeps on printing out the same exact thing again and again rather than increasing the date or the month. I've tried to debug this but I'm not seeing where I'm going wrong, can anyone please let me know how to do this!
public static void main(String[] args) {
Date date = new Date();
int year = 1900+date.getYear();
int month = 1+date.getMonth();
int currDate = date.getDate();
String currDate1 = formatter(currDate);
String month1 = formatter(month);
String theDate = currDate1+month1+year;
while(palindromeChecker(theDate)){
if(month==12) {
year++;
month=1;
}
if(year%4 == 0 && year%100 !=0 && year%400 == 0) {
if (month == 2 && currDate == 29) {
month++;
currDate = 1;
}
}
else {
if (month == 2 && currDate == 28) {
month++;
currDate = 1;
}
}
switch (month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
if(currDate==31) month++; currDate=1; break;
case 4: case 6: case 9: case 11:
if(currDate==30) month++; currDate=1; break;
}
currDate++;
theDate = formatter(currDate)+formatter(month)+year;
System.out.println(theDate);
}
}
public static String formatter(int a){
return new DecimalFormat("00").format(a);
}
public static boolean palindromeChecker(String a){
String b = new StringBuilder(a).reverse().toString();
if(a.equals(b)) return false;
else return true;
}