lundi 26 octobre 2015

I wan to display tomorrows date following a given date

I want to display tomorrow date following a given date ( month date year) I have no experience of programming but I'm trying to get used to doing this. I coded this but its not even working and I am stuck on this. does anyone can take a look?

int Year, Month, Day;
int tYear, tMonth, tDay;

System.out.print("Enter the month [1 to 12]: ");
System.out.print("Enter the day of the month [1 to 31]: ");
System.out.print("Enter the year: ");

tDay = Day + 1;
tMonth = Month;
tYear = Year;

if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) {

    if (tDay > 31) {
        tMonth = Month + 1;
        tDay = 1;
    }
} else if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {

    if (tDay > 30) {
        tMonth = Month + 1;
        tDay = 1;
    }
} else {

    if ((Year % 4 == 0) && (!(Year % 100 == 0) || (Year % 400) == 0)) {

        if (tDay > 29) {
            tMonth = 3;
            tDay = 1;
        }
    } else {
        if (tDay > 28) {
            tMonth = 3;
            tDay = 1;
        }
    }
}

if (tMonth == 13) {
    tMonth = 1;
    tYear = Year + 1;
}

System.out.println("Today's date is: " + Month +
    "/" + Day + "/" + Year + ".");
System.out.println("Tomorrow's date will be: " + tMonth +
    "/" + tDay + "/" + tYear + ".");

Aucun commentaire:

Enregistrer un commentaire