Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question: A year is a leap year if it is divisible by 4. But if the year is divisible by 100, it is a leap year only when it is also divisible by 400.
- import java.util.Scanner;
- public class LeapYear {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- System.out.print("Type a year: ");
- int year = Integer.parseInt(reader.nextLine());
- int leap1 = year % 4;
- int leap2 = year % 100;
- int leap3 = year % 400;
- if (((leap1==0) && (leap2!=0))||(leap3==0)){
- System.out.println("The year is a leap year.");
- }else {
- System.out.println("The year is not a leap year.");
- }
- }
- }
Add Comment
Please, Sign In to add comment