Neerajchauhan56039
70 views
17 slides
May 18, 2024
Slide 1 of 17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
About This Presentation
it is a explanation part
Size: 108.46 KB
Language: en
Added: May 18, 2024
Slides: 17 pages
Slide Content
Flow of control: If normal flow of execution of program will be changed due to any statement this process is called flow of control. It can be changed using following statements. (A) Selection Statements: ( i ) If Statement: It work on a particular condition. If condition is true then it’s statement or block will execute otherwise will not execute.
Syntax: if (expression) statement; OR if (expression) { statement1; statement 2; }
(ii) If … else Statement : It also work on a particular condition. If condition is true then it’s statement or block will execute otherwise else will execute. Syntax: if (expression) statement; OR else statement; if (expression) { statement1; statement 2; } else { statement1; statement 2; }
(iii) If … else if ladder Statement : Syntax: if (expression1) statement; else if (expression 2) statement; else statement;
(iv) Nested If Statement : A nested if is an if that has another if in its if’s body or its else’s body. Syntax: if (expression1) { if (expression 2) statement; } else { if (expression 2) statement; }
(B) Iteration Statement: It allow a set of instructions to be performed repeatedly until a certain condition is satisfied. The iteration statements are also called loops or looping statement that are three types. for loop, while loop and do – while loop
for loop: Syntax: for( delcaration / initilization ; condition; updattion ) { body of loop; }
for Loop Variations: ( i ) Multiple initialization and update: EX : int i, j; for(i=1, j=2;i<=5; i++, j++) OR for(int i=1, j=2;i<=5; i++, j++)
(ii) Optional expression: EX- 1: int i=2, j=3; for( ;i<=5; i++, j++) EX- 2: int i=2; for( ;i<=5; ) { i =i+2; }
while loop: Syntax: while(condition) { body of loop; update } It can be empty and infinite loop.
do-while loop: It is an exit control Syntax: do { body of loop; update } while(condition); It can be empty and infinite loop.
Note: The for loop is appropriate when we know in advance how many times the loop will execute. while and do while loops are more suitable in the situations where it is not known before – hand when the loop will terminate.
Jump statements: The jump statements unconditionally transfer program control within a function. Java have three main jump statements: return : ( It used to return from a function) break : (Skip or terminate the rest of loop) continue : ( skip the rest of loop statements and cause the next iteration of the loop)
Programs: Q.1) WAP to calculate the factorial of an integer. Q.2) WAP to calculate and print the sums of even and odd integers of the first n natural numbers. Q.3) WAP to check whether year is a leap year or not. Q.4) WAP to check whether the given number is palindrome or not.
Programs: Q.5) Write a program to find LCM and GCD of two numbers. Q.6) WAP to find the sum of the series : Q.7) WAP to print a tribonacci series( Whose first three terms are given and every next term is sum of previous three terms). Example: 0 1 2 3 6 11 20 27