Guest User

Untitled

a guest
Jul 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public static int dayOfWeek(int month, int day, int year) {
  2. int n;
  3. n = day;
  4. n += 2*month;
  5. n += (3*(month+1)/5);
  6. n += year;
  7. n += year/4;
  8. n -= year/100;
  9. n += year/400;
  10. n += 2;
  11. return n%7;
  12. }
  13.  
  14. public static void testDayOfWeek() {
  15. System.out.print("Testing dayOfWeek... ");
  16. // On 2/5/2006, the Steelers won Super Bowl XL on a Sunday!
  17. assert(dayOfWeek(2, 5, 2006) == 1);
  18. // On 6/15/1215, the Magna Carta was signed on a Monday!
  19. assert(dayOfWeek(6, 15, 1215) == 2);
  20. // On 3/11/1952, the author Douglas Adams was born on a Tuesday!
  21. assert(dayOfWeek(3, 11, 1952) == 3);
  22. // on 4/12/1961, Yuri Gagarin became the first man in space, on a Wednesday!
  23. assert(dayOfWeek(4, 12, 1961) == 4);
  24. // On 7/4/1776, the Declaration of Independence was signed on a Thursday!
  25. assert(dayOfWeek(7, 4, 1776) == 5);
  26. // on 1/2/1920, Isaac Asimov was born on a Friday!
  27. assert(dayOfWeek(1, 2, 1920) == 6);
  28. // on 10/11/1975, Saturday Night Live debuted on a Saturday (of course)!
  29. assert(dayOfWeek(10, 11, 1975) == 7);
  30. System.out.println("Passed all tests!");
  31. }
Add Comment
Please, Sign In to add comment