java - Why won't the value of my int change? -
hi i'm new java , working on code works calendar. thought had completed days seem remain 31 rather changing based on if/else statement. here code:
public int maxdaysinmonth( int year, int month ) { boolean = (year % 4 == 0) || ((year%4==0) && (year % 100 != 0)); int days = 0; int imonth = 0; if( imonth == 4 || imonth == 6 || imonth == 9 || imonth == 11) { days = 30; } else if ( imonth == 1 || imonth == 3 || imonth == 5 || imonth == 7 || imonth == 8 || imonth == 10 || imonth == 12) { days = 31; } if (a == true && imonth == 2) { days = 29; } else if (a == false && imonth == 2) { days = 28; } return days; }
any appreciated!
what's purpose of imonth
? initialize 0
test if represented month.
you don't need imonth
; use month
in if
tests.
also, leap year determination isn't quite correct. it's leap year if year number divisible 400
. try
boolean = (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
you might want more descriptive variable name, such isaleapyear
.
Comments
Post a Comment