Загрузка...

Check Leap Year Using Ternary Operator | Beginner Friendly

In this video, I demonstrate a simple Java program to check whether a given year is a leap year or not using logical operators and the ternary operator.

🎯 Purpose of this program

The main goal of this program is to understand how to use conditions and logical operators to solve real-world problems like checking leap years.

💻 Code Explanation
int y = new java.util.Scanner(System.in).nextInt();

➡️ This line takes the year as input from the user using the Scanner class.

boolean leap = (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0);

➡️ This line checks whether the year is a leap year using conditions:

If the year is divisible by 400 → Leap year
OR if divisible by 4 AND not divisible by 100 → Leap year
System.out.println(leap ? "Leap Year" : "Not Leap Year");

➡️ This uses the ternary operator:

If leap is true → prints "Leap Year"
Otherwise → prints "Not Leap Year"

📘 What you will learn
Taking input using Scanner
Using logical operators (&&, ||)
Understanding leap year logic
Using ternary operator in Java
Writing clean and efficient conditions

📌 This is an important beginner-level problem that improves your logical thinking and coding skills.

💡 Learning these conditions helps you solve many real-world programming problems.

Keep learning and building your Java knowledge 🚀



#Java #JavaProgramming #LeapYear #TernaryOperator #BeginnerJava #CodingForBeginners #LearnJava #JavaTutorial #ProgrammingBasics #LogicalOperators #DSA #CodingPractice #SaumizCodex

Видео Check Leap Year Using Ternary Operator | Beginner Friendly канала saumizcodex
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять