🔒 Closed FUN CODING PROBLEMS for beginners (Find the Day of the Week)

Status
Not open for further replies.

cetmyeval69

Honorary Poster
fvg.PNG

COMMENT YOUR SOLUTIONS!!

[CODE lang="java" title="SOLUTION"]class Solution {

final String[] weekDay = {"Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"};
final int[] days = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};

public String dayOfTheWeek(int day, int month, int year) {
if (isLeapyear(year) && (month > 2)) {
return (setWeekday(year, month, day, 1));
} else {
return (setWeekday(year, month, day, 0));
}
}

boolean isLeapyear(int year) {
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

String setWeekday(int year, int month, int day, int leap_day) {
return weekDay[((numOfDays(year) + ((days[(month - 1)]) + day)) + leap_day) % 7] + "day";
}

int numOfDays(int year) {
int leap = 0;
for (int i = 1809; i < year; i++) {
if (isLeapyear(i)) {
leap++;
}
}
return (leap * 366) + ((year - 1809) - leap) * 365 - 1;
}

}[/CODE]
 
Javascript

function returnDate(day,month,year) { const newDay = new Date(day,month,year).getDay() return ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'][newDay - 1] } returnDate(31,9,2019)
 
Status
Not open for further replies.

About this Thread

  • 8
    Replies
  • 463
    Views
  • 7
    Participants
Last reply from:
Yuuji-kun

Trending Topics

Online now

Members online
1,247
Guests online
2,307
Total visitors
3,554

Forum statistics

Threads
2,332,198
Posts
29,263,307
Members
1,146,126
Latest member
justrandomm
Back
Top