SeanNers

DisplayLeapYear

Aug 15th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package vn.com.hoangminh.Physics;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.util.Scanner;
  5.  
  6. public class DisplayLeapYear {
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9. System.out.print("Nhập năm đầu : ");
  10. int start = input.nextInt();
  11. System.out.print("Nhập năm cuối : ");
  12. int end = input.nextInt();
  13.  
  14. DisplayLeapYear display = new DisplayLeapYear();
  15. display.compute(start,end);
  16. }
  17.  
  18.  
  19. public void compute(int start, int end) {
  20. int[] nhap = new int[end];
  21. int[] output = new int[end];
  22. int j = 0;
  23.  
  24. for(int i = start; i <= end; i++) {
  25. if( i % 400 == 0 ) {
  26. output[j] = i;
  27. j++;
  28. }
  29. else if( i % 100 != 0 && i % 4 == 0 ) {
  30. output[j] = i;
  31. j++;
  32. }
  33. }
  34.  
  35. System.out.println("Các năm leap là : ");
  36.  
  37. for(int a = 0; a <= j; a++) {
  38. System.out.print( output[a] + " ");
  39. if( a % 8 == 7 ) System.out.print("\n");
  40.  
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment