object oriented programmingswitch the switch statement is java’s multiway branch statement. the...
TRANSCRIPT
![Page 1: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/1.jpg)
Object Oriented Programming
Lecture # 9-10
![Page 2: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/2.jpg)
Contents
Control Structures
Conditional statements
If
If . . .else
Switch
Nested If
Iteration Statement
For
While
Do . . . while
![Page 3: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/3.jpg)
Control Structures
The execution of the program is linear.
Control Structures are used to alter/change the flow of program.
![Page 4: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/4.jpg)
Selection Statements
There are three selection statements supported by java
1. If
2. If . . .else
3. switch
![Page 5: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/5.jpg)
Selection Statements
![Page 6: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/6.jpg)
Selection Statements
![Page 7: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/7.jpg)
Selection Statements
![Page 8: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/8.jpg)
Selection Statements
![Page 9: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/9.jpg)
Selection Statements
Nested if
A nested if is an if statement that is the target of another if or else.
if(condition1){
if(condition2){}if(condition3){}
}
![Page 10: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/10.jpg)
Selection Statements
![Page 11: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/11.jpg)
Selection Statements
![Page 12: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/12.jpg)
Selection Statements
![Page 13: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/13.jpg)
Selection Statements
![Page 14: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/14.jpg)
Selection Statements
Switch
The switch statement is Java’s multiway branch statement.
The expression must be of type byte, short, int, or char.
If none of the constants matches the value of the expression, then the default statement is executed.
The default statement is optional.
![Page 15: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/15.jpg)
Selection Statements
![Page 16: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/16.jpg)
Class Activity
Write a program that prints the designation of the employee according to their pay scale:
10000 – 20000 Manager Operations 20000 – 30000 Manager 30000 – 40000 Area Manager 40000 – 50000 Regional Manager
![Page 17: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/17.jpg)
Iteration Statements
While
A while statement repeats action again and again as long as a controlling boolean expression is true.
When condition becomes false, control passes to the next line of code immediately following the loop.
Syntax
while(condition) {// body of loop
}
![Page 18: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/18.jpg)
Iteration Statements
![Page 19: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/19.jpg)
Iteration Statements
![Page 20: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/20.jpg)
Iteration Statements
Do...While
The body of a do-while loop is always executed at least once.
Syntax
do{First_StatementSecond_Statement. . .Last_Statement
} while(Boolean_Expression);
![Page 21: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/21.jpg)
Iteration Statements
![Page 22: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/22.jpg)
Iteration Statements
![Page 23: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/23.jpg)
Iteration Statements
For
Syntax
for(initialization; condition; iteration) {// body}
The loop first starts, the initialization portion of the loop is executed and sets the value of the loop control variable.
The condition is evaluated and this must be a Boolean expression.
Iteration is an expression that increments or decrements the loop control variable.
![Page 24: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/24.jpg)
Iteration Statements
![Page 25: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/25.jpg)
Iteration Statements Nested loops
![Page 26: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/26.jpg)
Class Activity
Generate a series of Odd number and even number using for and while loop.
Generate alphabets from A to Z. ASCII code for A=65 and Z=90.
Calculate factorial when a number is supplied on runtime.
![Page 27: Object Oriented ProgrammingSwitch The switch statement is Java’s multiway branch statement. The expression must be of type byte, short, int, or char. If none of the constants matches](https://reader033.vdocument.in/reader033/viewer/2022053008/5f0bdd897e708231d4329893/html5/thumbnails/27.jpg)
Thank You!