アットウィキロゴ

ouchi > Practice > Study02-03

  1. import java.util.Scanner;
  2.  
  3. /** うるう年の判定を行います **/
  4. public class LeapYear {
  5. public static void main(String[] args) {
  6. int year;
  7. Scanner scan = new Scanner(System.in);
  8. System.out.print("西暦で年を入力: ");
  9. year = scan.nextInt();
  10.  
  11. boolean result;
  12. if (year % 4 == 0) {
  13. if (year % 100 == 0) {
  14. if (year % 400 == 0) {
  15. result = true;
  16. } else {
  17. result = false;
  18. }
  19. } else {
  20. result = true;
  21. }
  22. } else {
  23. result = false;
  24. }
  25.  
  26. if (result) {
  27. System.out.println("うるう年");
  28. } else {
  29. System.out.println("平年");
  30. }
  31. }
  32. }
  33.  
最終更新:2013年05月15日 18:12