Sunday 16 August 2015

WAP in java to check whether the entered year is leap year or not using conditional operators.

//Check Leap year using conditional operators

import java.util.Scanner;

class Leap_year {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a year:");
int yr=sc.nextInt();

String result=((yr%100==0 && yr%400==0)||(yr%100!=0 && yr%4==0))?"a Leap Year.":"not a Leap year";

System.out.println("It is "+result);
}
}

No comments:

Post a Comment