Loading…
1. Variables and Operators in Java
A variable is used to store data, and operators perform operations on these variables.
Example: Arithmetic Operators
Explanation:
+(Addition),-(Subtraction),*(Multiplication),/(Division),%(Modulo) are used to perform arithmetic calculations.
2. Control Flow Statements in Java
Control flow statements decide the execution path of the program based on conditions.
Example: If-Else Statement
Explanation:
ifchecks a condition; iftrue, it executes the block inside{ }.- If
false, it moves toelseblock.
Example: Switch Case
Explanation:
- The
switchstatement is used when we have multiple possible values for a variable. breakensures the program exits after finding the correct case.
Example: Loops (for, while, do-while)
For Loop:
Explanation:
forloop repeats execution fromi = 1toi = 5.
While Loop:
Explanation:
whileloop runs until the condition (i <= 5) becomesfalse.
Do-While Loop:
Explanation:
- The
do-whileloop ensures the code runs at least once, even if the condition isfalse.
Summary:
✅ Variables store values.
✅ Operators perform calculations.
✅ If-else decides execution based on a condition.
✅ Switch handles multiple choices.
✅ Loops repeat tasks multiple times.
These basics are the foundation of Java programming! 🚀
Comments
Post a Comment