Lesson 8 of 34

&&, || மற்றும் !: Conditions-ஐ இணைத்தல்&&, || and !: Combining Conditions

8 min 25 XP

&& (AND): இரண்டும் true ஆக இருந்தால் மட்டும் true. || (OR): ஏதேனும் ஒன்று true ஆனால் true. ! (NOT): true-ஐ false ஆகவும், false-ஐ true ஆகவும் மாற்றும்.

&& (AND) is true only when both sides are true. || (OR) is true when either side is true. ! (NOT) flips true to false and false to true.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

சிறிய if/else-ஐ ternary operator மூலம் ஒரே வரியில் எழுதலாம்: condition ? மதிப்பு1 : மதிப்பு2

A small if/else can be written on one line with the ternary operator: condition ? value1 : value2

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Challenge

+25 XP

ஒரு வருடத்தைப் (year) படித்து, அது leap year ஆக இருந்தால் "Leap year", இல்லையெனில் "Not a leap year" என்று print செய்யுங்கள். விதி: 400-ஆல் வகுபட்டால் leap; அல்லது 4-ஆல் வகுபட்டு 100-ஆல் வகுபடாவிட்டால் leap.

Read a year. Print "Leap year" if it is a leap year, otherwise "Not a leap year". Rule: divisible by 400, or divisible by 4 but not by 100.

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.