Computer Science, asked by 89hhgb, 1 year ago

write a program in Java to check whether are given year is leap year or not using nested ternary operator only....... Solve it with full steps

Answers

Answered by Aryendra
5
The logic will be as follows
First check if divisible by 400,if yes then it is a leap year,then if it's not check whether divisible by 100,if yes ,since it's already sure that it's not divisible by 400 it's not leap year,if it's not even divisible by 100 then check if divisible by 4 or not ,if yes then it's a leap year else not.
Now the code,
//is this year a leap year?
//--------------test expression-----result
$year=Integer.parseInt( in.readLine ());//inputting year
isLeapYear = (($year % 400) == 0) ? 1 :
((($year % 100) == 0)? 0 :
((($year % 4) == 0) ? 1 :
0));//
If (isLeapYear==1)
System.out.println ("leap year");
Similar questions