Hello!
I'm taking a class in JAVA and learning a lot, but i'm stumped on a project where we are to find the difference between two dates. The method iv'e used is a little unconventional, I don't know if there is aproblem with the way i've structured the loop below...
The y1 < y2 ? j++: j-- is supposed to acount for the user entering a date with alower value before a date with a higher year value or the other way around....because the first year being less than the second year, and the first year being equal to j, will force j to increment by one. Else it will decrement by 1 until j is equal to year 2.
for (j = y1; j != y2; y1 < y2 ? j++ : j--)
{
if(j % 4 == 0)
{
if (y1 % 100 != 0)
{
totalDays += 1;
return "The first year entered is a leap year\n.";
else if (y1 % 400 == 0)
{
totalDays += 1;
return "The first year entered is a leap year\n.";
}
}
else
totalDays = totalDays;
return "The first year entered is NOT a leap year\n.";
}
}
int yearsDifference = y2-y1;
totalDays += 365*yearsDiference;
}
}
The output I get:
DateDifference.java:148: not a statement
for (j = y1; j != y2; y1 < y2 ? j++ : j--)
^
DateDifference.java:156: 'else' without 'if'
else if (y1 % 400 == 0)
^
2 errors