Problem Statement

Write a program that accepts a positive integer that represents a year, and prints whether that year is a leap year or not. If the year is a leap year, it should print output similar to "2000 is a Leap Year". If not, it should print output similar to "2001 is not a Leap Year".

Leap Years

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is. - USNO

    

Write a program that accepts a positive integer that represents a year...

public class Example{
  public static void main(String[] args){
} }

Write a program that accepts a positive integer that represents a year...

// Load required classes
import java.util.Scanner;
import java.io.File;
public class Example{ public static void main(String[] args){
} }

Write a program that accepts a positive integer that represents a year...

// Load required classes
import java.util.Scanner;
import java.io.File;
public class Example{ public static void main(String[] args){ // Scanner variable Scanner reader;
// If an argument is present, // we are reading from a file // specified in args[0] if(args.length > 0){ reader = new Scanner(new File(args[0])); // If no argument, read from System.in }else{ reader = new Scanner(System.in); }
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */ } }

Write a program that accepts a positive integer that represents a year...

// Load required classes
import java.util.Scanner;
import java.io.File;
public class Example{ public static void main(String[] args) throws Exception{ // Scanner variable Scanner reader;
// If an argument is present, // we are reading from a file // specified in args[0] if(args.length > 0){ reader = new Scanner(new File(args[0])); // If no argument, read from System.in }else{ reader = new Scanner(System.in); }
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */ } }

Write a program that accepts a positive integer that represents a year...

// Load required classes
import java.util.Scanner;
import java.io.File;
public class Example{ public static void main(String[] args) throws Exception{ // Scanner variable Scanner reader;
// If an argument is present, // we are reading from a file // specified in args[0] if(args.length > 0){ reader = new Scanner(new File(args[0])); // If no argument, read from System.in }else{ reader = new Scanner(System.in); }
/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */ } }

Write a program that accepts a positive integer that represents a year...


    

Write a program that accepts a positive integer that represents a year...

int year = reader.nextInt();
    

Write a program that accepts a positive integer that represents a year...

int year = reader.nextInt();
    

Write a program that accepts a positive integer that represents a year...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
}

Write a program that accepts a positive integer that represents a year...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
}

Every year that is exactly divisible by four is a leap year, except...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
}

Every year that is exactly divisible by four is a leap year, except...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

Every year that is exactly divisible by four is a leap year, except...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...except for years that are exactly divisible by 100, but...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...except for years that are exactly divisible by 100, but...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      System.out.println("no");
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...except for years that are exactly divisible by 100, but...

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      System.out.println("no");
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      System.out.println("no");
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      System.out.println("no");
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.

int year = reader.nextInt();
if(year <= 0){
  System.out.println("Error");
}else{
  if(year % 4 == 0){
    //divisible by 4
    if(year % 100 == 0){
      //divisible by 4 and 100
      if(year % 400 == 0){
        //divisible by 4 and 100 and 400
        System.out.println("yes");
      }else{
        //divisible by 4 and 100 not 400
        System.out.println("no");
      }
    }else{
      //divisible by 4 but not 100
      System.out.println("yes");
    }
  }else{
    //not divisible by 4
    System.out.println("no");
  }
}
    

...positive integer that represents a year...
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400.