leap year using conditional operator in java

Solutions on MaxInterview for leap year using conditional operator in java by the best coders in the world

showing results for - "leap year using conditional operator in java"
Arianna
03 Nov 2020
1// Leap year using conditional operator in java
2import java.util.Scanner;
3public class LeapYearExample 
4{
5   public static void main(String[] args) 
6   {
7      long number, year, a;
8      Scanner sc = new Scanner(System.in);
9      System.out.println("Please enter any year :");
10      year = sc.nextLong();        
11      if(year != 0)
12      {
13         number = (year % 400 == 0)?(a = 1):((year % 100 == 0)?(a = 0):((year % 4 == 0)?(a = 1):(a = 0)));      
14         if(number == 1)
15         {
16            System.out.println(year + " is a leap year");
17         }
18         else
19         {
20            System.out.println(year + " is not a leap year");
21         }
22      }
23      else
24      {
25         System.out.println("year zero does not exist ");
26      }
27      sc.close();
28   }
29}
Nino
16 Feb 2016
1import java.util.Scanner;public class Main{public static void main(String[] args){int year;System.out.println("Enter the year");Scanner sc = new Scanner(System.in);year = sc.nextInt();if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))System.out.println("it is a leap year");elseSystem.out.println("it is not a leap year");}}