#java

53 messages · Page 1 of 1 (latest)

full saffron
#

computes the number of months, weeks, and days in a given amount of days java

hardy birchBOT
#

Hey, @full saffron!
Please remember to /close this post once your question has been answered!

full saffron
#

computes the number of months, weeks, and days in a given amount of days java

#

can someone help me with the code

azure marsh
#

try to think about it mathematically, how would you tell from a number of days, how many months, weeks, and days they are

full saffron
azure marsh
#

lets start with the months, lets say you have 90 days, how many months does that have?

full saffron
#

3

azure marsh
#

how do you get from 90 to 3?

full saffron
#

There are 30 days in a month

#

so 90 days is three month

azure marsh
#

yep, so you would divide 90 by 30 to get 3

full saffron
#

yeah how i can right that

#

Sorry but i'm a beginner

azure marsh
#

no problem! In Java you would divide by doing: 90 / 30.

#

assuming you use integers a division always rounds down

full saffron
#

like this ?

azure marsh
#

so if you had 105/30, which technically would equal 3.5, since you divide integers and rounding down 3.5 would equal 3

azure marsh
full saffron
#

okey what about weeks

#

i know how its work but i don't know how to write it

azure marsh
#

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

full saffron
#

how can i do that

azure marsh
#

days -= months * 30

full saffron
azure marsh
#

try not using the %365 at first

#

since its not asked for in the question

full saffron
#

so how can i write that without %365

azure marsh
#

just remove it, you dont need it at all

#

int months = day/30;

full saffron
#

what about days

azure marsh
#

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

full saffron
#

yeah how can i remove months

azure marsh
full saffron
#

under int months ?

azure marsh
#

yes

full saffron
#

okey

azure marsh
#

now basically the same thing with weeks, and then day will be the days that are left over

full saffron
#

day -= weeks * 7 ?

#

what should i write here

azure marsh
#

from the variable day you have removed the days that are accounted for by the months and the weeks, what is left?

full saffron
#

the days

azure marsh
#

exactly

full saffron
#

how can i write that

azure marsh
#

int days = day;

full saffron
#

bro thank u so much for helping me

azure marsh
#

np ^^

full saffron
#

❤️ ❤️