#java
53 messages · Page 1 of 1 (latest)
Hey, @full saffron!
Please remember to /close this post once your question has been answered!
computes the number of months, weeks, and days in a given amount of days java
can someone help me with the code
try to think about it mathematically, how would you tell from a number of days, how many months, weeks, and days they are
I have a problem with writing the equation
lets start with the months, lets say you have 90 days, how many months does that have?
3
how do you get from 90 to 3?
yep, so you would divide 90 by 30 to get 3
no problem! In Java you would divide by doing: 90 / 30.
assuming you use integers a division always rounds down
like this ?
so if you had 105/30, which technically would equal 3.5, since you divide integers and rounding down 3.5 would equal 3
pretty much
i would remove the days ,that are accounted for by the months, from the total number of days, and then do the same thing you did with the months, only with 7
how can i do that
days -= months * 30
so how can i write that without %365
lets do weeks first
at the moment you get the total amount of weeks, but you only want the weeks that are left over after the maximum number of months are accounted for
yeah how can i remove months
.
under int months ?
yes
now basically the same thing with weeks, and then day will be the days that are left over
from the variable day you have removed the days that are accounted for by the months and the weeks, what is left?
the days
exactly
how can i write that
int days = day;
bro thank u so much for helping me
np ^^
❤️ ❤️