Paper Title: Java programming
Programme BCA
Subject Computer Science
Course 24MJBCA3L1
Code
Semester III
University Vijayanagara Sri Krishnadevaraya University, Ballari
(VSKUB)
Created by Dr. Halkar Rachappa
Session 5
Assignment Operators &
Unary Operators
Assignment Operators
=, +=, -=, *=, /=, %=, etc.
Example:
int x = 5;
• x += 3; // x = x + 3
• Unary Operators
+, -, ++, --, !
Example:int a = 10;
System.out.println(++a); // 11
Bitwise Operators Ternary Operator
• Bitwise Operators
&, |, ^, ~, <<, >>, >>>
Example:
• System.out.println(5 & 3); // 1
• Ternary Operator
Syntax: condition ? true Expression : false Expression
Example:
int a = 10, b = 20;
• int max = (a > b) ? a : b;
Control Structures in Java
• Decision-making Statements (Conditional)
• Looping Statements (Iteration)
• Branching Statements (Jumping)
Decision-Making Statements
Statement Description Example
Executes if the condition is if (a > b)
if
true { System.out.println(a); }
if-else Executes either if or else if (a > b) { ... } else { ... }
block
else if if (...) { ... } else if (...) { ... }
Checks multiple conditions
else { ... }
int day = 2;
switch (day) {
case 1: System.out.println("Monday");
break;
Selects one block from case 2: System.out.println("Tuesday");
switch break;
many cases default: System.out.println("Other
day");
}
Looping Statements
Example
Loop Type Description
for Loop with initialization, condition, for (int i = 0; i < 5; i++) { ... }
update Ex:
for (int i = 0; i < 3; i++) {
System.out.println("i = " + i);
}
while
Loop that runs while a condition
while (i < 5) { ... }
is true
do-while Loop that runs at least once do { ... } while (i < 5);
Branching Statements
Statement Description Example
Exits from a loop or switch
break
statement
for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
Skips the current iteration of if (i == 5) break;
continue
the loop System.out.println(i);
}
Exits from the method and
return
optionally returns a value
Thank you