i need to write a code that takes in input an integer called mese(this int goes from 0 to 5), this integer will be added to the current month, that becouse call this function when i need to get the last day of an exact month example, it's august and i need to know the last day of august + mese where mese =3 so i need to know the last day of august+3= november, so the function will return 30 in this case. here is my code, but i don't understand what's wrong(note that this is just a part of my real code)
public int getmax(int mese){
int res =0;
int giornocorr = Calendar.getInstance().get(Calendar.DATE);
int mesecorr = Calendar.getInstance().get(Calendar.MONTH);
int annocorr = Calendar.getInstance().get(Calendar.YEAR);
if ((mesecorr + 1) - mese == 0) {
// se siamo nel mese corrente
giornoFineMese = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
res = giornoFineMese - giornocorr;
System.out.println("days of this month: " + res);
} else {
// se non siamo nel mese corrente
Calendar c = Calendar.getInstance();
if ((mesecorr + 1 + mese) % 13 >= mesecorr) {// current year
c.set(Calendar.MONTH, mesecorr + 1 + mese);
c.set(Calendar.YEAR, annocorr);
} else {// next year
c.set(Calendar.MONTH, mesecorr + 1 + mese);
c.set(Calendar.YEAR, annocorr + 1);
}
c.add(Calendar.MONTH, mese);
c.set(Calendar.DATE, c.getMaximum(Calendar.DATE));
res = c.getActualMaximum(Calendar.DATE);
System.out.println("days of month " +c.get(Calendar.MONTH)+" "+ res);
return res;
}
thanks to anyone who answers