//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);
}
}
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