Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class Solution {
  2.  
  3. public int getIndexByDay(String S) {
  4. switch(S) {
  5. case "Mon": return 0;
  6. case "Tue": return 1;
  7. case "Wed": return 2;
  8. case "Thu": return 3;
  9. case "Fri": return 4;
  10. case "Sat": return 5;
  11. case "Sun": return 6;
  12. }
  13. return -1;
  14. }
  15.  
  16. public static String[] initArray() {
  17. String[] arr = new String[7];
  18. arr[0] = "Mon";
  19. arr[1] = "Tue";
  20. arr[2] = "Wed";
  21. arr[3] = "Thu";
  22. arr[4] = "Fri";
  23. arr[5] = "Sat";
  24. arr[6] = "Sun";
  25. return arr;
  26. }
  27.  
  28. public String solution(String S, int k) {
  29. String[] arr = initArray();
  30. int currentIndex = getIndexByDay(S);
  31. int toAdd = k % 7;
  32. int indexDayToBe = (currentIndex + toAdd) % 7;
  33. return arr[indexDayToBe];
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement