Thursday, 10 September 2020

leap year or not(Nested-if)

Write a Java Program to find given number is Leap or Not using Nested if statement 
import java.util.Scanner;
public class Leap 
{
	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		System.out.println("Enter Year: ");
		int year = s.nextInt();
		if ( year % 4 == 0) 
		{
		        if (year%100 == 0) 
			{
			   if(year%400 == 0) 
			   {	
			   System.out.println("\n"+year+" is a Leap Year. ");
			   }
			   else 
			   {
			   System.out.println("\n"+year+" is a NOT Leap Year.");
			   }
			}
			else 
			{
			    System.out.println("\n"+year+" is a Leap Year. ");
			}
		}
		else 
		{
		   System.out.println("\n"+year+" is a NOT Leap Year. ");
		}
	  }
}
Output:

1 comment:

If you have any doubts, please let me know

Pattern 31 & 32