- How to Check if a year is Leap Year
- Question Picked ✔️ ✔️: Write a program to print leap years from 2000 to 2021
Table of Contents expand_more
How to Check if a year is Leap Year
Example

Code
//By GadTool.blogspot.com
import java.util.Scanner;
class
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int GadTool;
System.out.println("Enter the year:");
GadTool=sc.nextInt();
if(GadTool%4==0){
System.out.println("LEAP YEAR");
}else {
System.out.println("Year is not a leap year");
}
}
}
import java.util.Scanner;
class
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int GadTool;
System.out.println("Enter the year:");
GadTool=sc.nextInt();
if(GadTool%4==0){
System.out.println("LEAP YEAR");
}else {
System.out.println("Year is not a leap year");
}
}
}
➡️ Enter the name of the class in which you are typing or pasting the above code.
Question Picked ✔️ ✔️: Write a program to print leap years from 2000 to 2021

Code
//By GadTool.blogspot.com
class
{
public static void main()
{
int GadTool;
System.out.println("Leap Year list from 2000 to 2021:");
for(GadTool=2000;GadTool<=2021;GadTool++){
if(GadTool%4==0){
System.out.println(GadTool);
}
}
}
class
{
public static void main()
{
int GadTool;
System.out.println("Leap Year list from 2000 to 2021:");
for(GadTool=2000;GadTool<=2021;GadTool++){
if(GadTool%4==0){
System.out.println(GadTool);
}
}
}
➡️ Enter the name of the class in which you are typing or pasting the above code.
Explanation
First of all, we have initialized an integer named GadTool to carry the years from 2000 to 2021 as its value. Then we printed the heading of the program.
Subsequently, for loop is added so that it could run a check on every value of the variable GadTool .
Java Program for loop in a Nutshell⇾
1. Initialization-: We assigned 2000 as the initial value of the variable GadTool .2. Test Condition-: We added a condition that the loop can only continue if the value of variable GadTool is less than or equal to 2021.
3. Body of the loop-: We added an if statement to execute when the value of the division of variable GadTool by 4 is giving the remainder of zero (0), meaning that if the value of variable GadTool is a leap year, then print the current value of variable GadTool .
4. Update Statement-: After the body of the for loop is executed then do GadTool++ , this means that the loop increases the value of variable GadTool with 1.
The for loop continues until the value of GadTool is less than or equal to the limit of 2021.
2 Comments
Thank you so much. But I want you to also make an article to how I can get a list of all Leap Years between 2000 to 2021 using Java and JavaScript !!!
ReplyDeleteI am waiting for the same article
Sure!!
Delete