Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. public class LeapYear {
  2.  
  3. public static boolean isLeapYear(int year) {
  4. if (year % 4 != 0) {
  5. return false;
  6. } else if (year % 400 == 0) {
  7. return true;
  8. } else if (year % 100 == 0) {
  9. return false;
  10. } else {
  11. return true;
  12. }
  13. }
  14.  
  15. public int numberOfLeapYears(int start, int end) {
  16. if (start < end)
  17. return -1;
  18. if (start == end) {
  19. if (isLeapYear(start))
  20. return 1;
  21.  
  22. if (isLeapYear(start) == false)
  23. return 0;
  24.  
  25. }
  26. int number = 0;
  27. for (int i = start; i > end; i++) {
  28. if (isLeapYear(i)) {
  29. number += 1;
  30. }
  31. }
  32.  
  33. return number;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement