java - Need help method calling program - day number in year -
basically in middle of programme involves asking user come in day,month, , year, , based on entry supposed create method calculates number of days in year, of course of study need method defines how many days in each month, , method determines whether or not jump year or not. have established methods, user input, having method/return issue. here have far:
import java.util.scanner; public class daynumber{ public static void main(string[] args){ int year; int month; int day; scanner keyboard = new scanner(system.in); system.out.print("enter date's year (0001 - 9999): "); year = keyboard.nextint(); system.out.print("enter date's month (1 - 12): "); month = keyboard.nextint(); system.out.print("enter date's day (1 - 31): "); day = keyboard.nextint(); } public static int numberofdays(int day, int month, int year){ int numberofdays; homecoming numberofdays; } public static int daysinmonth(int month, int year){ int daysinmonth; if (month ==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){ month = 31;} if (month ==4 || month ==6 || month==9|| month==11){ month = 30;} else if (month ==2){ if (){ } } homecoming daysinmonth; } public static boolean isleapyear(int year){ if (((year%4 == 0) && (year%100 != 0)) || (year%400 ==0)){ homecoming true; } else{ homecoming false; } } }
i appreciate advice or tips. new java go ahead , critique away! thanks.
there several different ways. yours looks fine me.
but favorite tiny little line :
daysinmonth = (month === 2) ? (28 + isleapyear) : 31 - (month - 1) % 7 % 2;
if asking : why % 7 % 2 ?
well, have noticed starting august, pattern reverted, that's doing here. between 0 - 6 it's normal if it's 7 (7 % 7 = 0) going beggining). % 2 alternate between 0 - 1.
hope made myself clear
java
No comments:
Post a Comment