DMCA.com Protection Status Java Programming Lesson 3 | Operators in Java Tutorial - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

Java Programming Lesson 3 | Operators in Java Tutorial

 LESSON-3: OPERATORS

Welcome to Lesson-3: Operators in Java 👨‍💻✨


📘 Lesson 3 — Operators (Arithmetic, Logical, Relational)

Operators → Symbols used to perform operations on data.

Example:

a + b

Here + is an operator


✅ 1️⃣ Arithmetic Operators

Used for math operations:

OperatorMeaning       Example
+         Addition        a + b
-        Subtraction        a - b
*        Multiplication        a * b
/        Division        a / b
%        Modulus (remainder)        a % b

✅ Example Code:

public class ArithmeticExample { public static void main(String[] args) { int a = 10, b = 3; System.out.println("Addition: " + (a + b)); System.out.println("Subtraction: " + (a - b)); System.out.println("Multiplication: " + (a * b)); System.out.println("Division: " + (a / b)); System.out.println("Remainder: " + (a % b)); } }

✅ 2️⃣ Relational / Comparison Operators

Used to compare values → Output: true / false

OperatorMeaning     Example
==      Equal to      a == b
!=      Not equal      a != b
>     Greater than      a > b
<     Less than      a < b
>=     Greater or equal      a >= b
<=     Less or equal      a <= b

✅ Example:

int a = 10, b = 20; System.out.println(a > b); // false

✅ 3️⃣ Logical Operators

Used in conditions (true or false)

Operator    MeaningExample
&&     AND       (age > 18 && age < 30)
`      `
!     NOT       !(isStudent)

✔ Logical AND → both true
✔ Logical OR → any one true
✔ NOT reverses truth


✅ Full Practical Example

public class OperatorsExample { public static void main(String[] args) { int x = 15, y = 10; System.out.println("x + y = " + (x + y)); System.out.println("x > y: " + (x > y)); System.out.println("x == y: " + (x == y)); System.out.println("Logical AND (x>10 && y<20): " + (x > 10 && y < 20)); } }

✅ Output:

x + y = 25 x > y: true x == y: false Logical AND (x>10 && y<20): true

🧠 Bonus: Increment / Decrement Operator

Operator      Meaning
++        Add 1
--        Subtract 1
int a = 5; a++; // a = a + 1 => 6 a--; // a = 5

📝 Exercise for You (Try Now ✅)

Write a program:

Input:

a = 50 b = 20

Output must show:

✅ Sum
✅ Difference
✅ a > b ?
✅ a == b ?
✅ (a > 30 AND b < 25)

Reply with your code + result
I will check and grade it ✅


🎯 Quick Quiz

1️⃣ Which operator gives remainder?
A) /
B) %
C) *

2️⃣ Which operator returns TRUE only when both conditions are TRUE?
A) &&
B) ||
C) !

Reply like:
1 → ?, 2 → ?


✅ Lesson-3 Complete!

Reply with:
✅ Exercise code
✅ Quiz answers

➡ and then we go to Lesson-4: Conditional Statements (if, else, switch) 🚀


▶ NEXT PART - Lesson-4: Conditional Statements

No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.