Thursday 10 September 2020

leap year or not (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("\n Enter Year: ");
		int Year = s.nextInt();
			if((Year%4==0&&Year%100!=0)||Year%400==0)
			{
			System.out.println("\n "+Year + " is Leap Year");
			}
			else
			{
			System.out.println("\n "+Year+" is a NOT Leap Year. ");
			}
	}
}
Output:

Enter Year: 

2022

2022 is a NOT Leap Year. 

  1. Write a Java Program to find given number is Leap or Not using if
  2. Write a Java Program to find given number is Leap or Not using else-if.
  3. Write a Java Program to find given number is Leap or Not using Nested if statement
  4. Write a Java Program to find given number is Leap or Not using method

No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32