Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /**
  2. * Gavin Foyle
  3. * Assignment 1 Question 2
  4. * Version 1.0
  5. * 9-22-17
  6. */
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Question2 {
  11.  
  12. public static void main(String[] args) {
  13.  
  14. int year, day, month, date, j,k;
  15.  
  16.  
  17.  
  18.  
  19. System.out.println("Day of the week Calculator");
  20. System.out.println("__________________________");
  21.  
  22. Scanner input1 = new Scanner(System.in);
  23. System.out.println("Please enter a year (numerically)");
  24. System.out.println();
  25. year = input1.nextInt();
  26. System.out.println("Please enter a month 1-12 (numerically)");
  27. month = input1.nextInt();
  28. System.out.println("Please enter a day 1-31 (numerically)");
  29. day = input1.nextInt();
  30.  
  31. if (month <= 2) month += 12;
  32.  
  33. String monthString = "";
  34.  
  35. if (month==1) {month <= 31;
  36.  
  37. if (month==2) month <= 28;
  38.  
  39. if (date==3) month <= 31;
  40.  
  41. if (month==4) month = <= 30;
  42.  
  43. if (month==5) month <= 31;
  44.  
  45. if (month==6) month <= 30;
  46.  
  47. if (month==7) month <=31;
  48.  
  49. if (month==8) month <= 31;
  50.  
  51. if (month==9) month <= 30;
  52.  
  53. if (month==10) month <= 31;
  54.  
  55. if (month==11) month <= 30;
  56.  
  57. if (month==12) month <= 31;
  58.  
  59.  
  60. k = year % 100;
  61. j = year / 100;
  62.  
  63.  
  64. date = ((day + (((month + 1) * 26) / 10) + k + (k / 4) + (j / 4)) + (5*j)) % 7 ;
  65.  
  66.  
  67.  
  68.  
  69. String str = "";
  70.  
  71. if (date==0) str="Saturday";
  72.  
  73. if (date==1) str="Sunday";
  74.  
  75. if (date==2) str="Monday";
  76.  
  77. if (date==3) str="Tuesday";
  78.  
  79. if (date==4) str="Wednesday";
  80.  
  81. if (date==5) str="Thursday";
  82.  
  83. if (date==6) str="Friday";
  84.  
  85. System.out.println("That date was a "+str+ ".");
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. }
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement