SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
Conversion to String, Flow of Control: Sequential, Conditional, Iterative
• Converting byte to String:
byte a=100;
String s=Byte.toString(a);
• Converting short to String:
short a=1000;
String s=Short.toString(a);
• Converting int to String:
int a=10000;
String s=Integer.toString(a);
• Converting long to String:
long a=100000;
String s=Long.toString(a);
• Converting float to String:
float a=10.156F;
String s=Float.toString(a);
• Converting double to String:
double a=10.156;
String s=Double.toString(a);
• Converting Boolean to String:
boolean a=true;
String s=Boolean.toString(a);
In computer science, control flow (or alternatively, flow of control) refers to the
specification of the order in which the individual statements, instructions or function calls
of an imperative program are executed or evaluated.
There are three types of Flow of Control:
• Sequential- Statements executes one after the other
• Conditional- if condition satisfies, then only the statement executes
• Iterative- statements execute more than once
• if statement:
Syntax:
if(condition)
{
//statements
}
When condition evaluates to true then its corresponding statements are executed
For example:
int a=4;
if(a%2==0)
System.out.print(“Number is even”);
It will print: Number is even as condition is true
• if else statement
Syntax:
if(condition)
{
// statements
}
else{
// statements
}
When condition evaluates to true then its corresponding statements of if block are
executed, otherwise statements of else block are executed
For example:
int a=7;
if(a%2==0)
System.out.print(“Number is even”);
else
System.out.print(“Number is odd”);
It will print: Number is odd as condition evaluates to false, so else part is executed
• else if statement
Syntax:
if(condition1)
{
// statements
}
else if(condition2){
// statements
}
…
else if(condition-n){
// statements
}
else{
//statements
}
For example:
int a=55;
if(a>=80&&a<=100)
System.out.print(“Grade A”);
else if(a>=60&&a<80)
System.out.print(“Grade B”);
else if(a>=40&&a<60)
System.out.print(“Grade C”);
else
System.out.print(“Grade D”);
It will print: Grade C
• switch statement:
Syntax:
switch(variable) //variable can be int, char, string
{
case value1:
//statements
break;
case value2:
//statements
break;
case value-n:
//statements
break;
default:
//statements
}
For example:
int a=5;
switch(a)
{
case 1:
System.out.print(“Hello”);
break;
case 2:
System.out.print(“Hi”);
break;
default:
System.out.print(“Default”);
break;
}
it will print: Default
• for loop is an entry controlled loop
Syntax:
for(initialisation;condition;increment/decrement)
{
//statements
}
For example:
for(int i=1;i<=5;i++)
System.out.print(i+” “);
it will print: 1 2 3 4 5
Here i is local to for loop only.
• while loop is an entry controlled loop
Syntax:
while(condition)
{
//statements
}
For example:
int i=1;
while(i<=5)
{
System.out.print(i+” “);
i++;
}
it will print: 1 2 3 4 5
• do while loop is an exit controlled loop
Syntax:
do
{
//statements
} while(condition);
For example:
int i=1;
do
{
System.out.print(i+” “);
i++;
} while(i<=5);
it will print: 1 2 3 4 5
do while will executes at least once even if the condition evaluates to false

Contenu connexe

Tendances

Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
alish sha
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
Amit Singh
 

Tendances (20)

Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentation
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 

En vedette

ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
deepsxn
 

En vedette (20)

Learn Java Part 4
Learn Java Part 4Learn Java Part 4
Learn Java Part 4
 
Stars
StarsStars
Stars
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 
Learn Java Part 6
Learn Java Part 6Learn Java Part 6
Learn Java Part 6
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Learn Java Part 7
Learn Java Part 7Learn Java Part 7
Learn Java Part 7
 
Learn Java Part 10
Learn Java Part 10Learn Java Part 10
Learn Java Part 10
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle Apps
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYST
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle apps
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
 
Java lesson khmer
Java lesson khmerJava lesson khmer
Java lesson khmer
 
ppt on scanner class
ppt on scanner classppt on scanner class
ppt on scanner class
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Java I/O
Java I/OJava I/O
Java I/O
 

Similaire à Learn Java Part 5

Similaire à Learn Java Part 5 (20)

Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
C# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.pptC# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.ppt
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
3. control statements
3. control statements3. control statements
3. control statements
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
 
Control structure
Control structureControl structure
Control structure
 
Session 3
Session 3Session 3
Session 3
 
C programming
C programmingC programming
C programming
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
C tutorial
C tutorialC tutorial
C tutorial
 
Bsit1
Bsit1Bsit1
Bsit1
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 

Plus de Gurpreet singh

Plus de Gurpreet singh (20)

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP Reporting
 
Why Messaging system?
Why Messaging system?Why Messaging system?
Why Messaging system?
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr Framework
 
Java Servlet part 3
Java Servlet part 3Java Servlet part 3
Java Servlet part 3
 
Oracle advanced queuing
Oracle advanced queuingOracle advanced queuing
Oracle advanced queuing
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
PL/SQL Part 5
PL/SQL Part 5PL/SQL Part 5
PL/SQL Part 5
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
 
PL/SQL Part 2
PL/SQL Part 2PL/SQL Part 2
PL/SQL Part 2
 
PL/SQL Part 1
PL/SQL Part 1PL/SQL Part 1
PL/SQL Part 1
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics Notes
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 

Dernier

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 

Learn Java Part 5

  • 1. Conversion to String, Flow of Control: Sequential, Conditional, Iterative
  • 2. • Converting byte to String: byte a=100; String s=Byte.toString(a); • Converting short to String: short a=1000; String s=Short.toString(a); • Converting int to String: int a=10000; String s=Integer.toString(a); • Converting long to String: long a=100000; String s=Long.toString(a);
  • 3. • Converting float to String: float a=10.156F; String s=Float.toString(a); • Converting double to String: double a=10.156; String s=Double.toString(a); • Converting Boolean to String: boolean a=true; String s=Boolean.toString(a);
  • 4. In computer science, control flow (or alternatively, flow of control) refers to the specification of the order in which the individual statements, instructions or function calls of an imperative program are executed or evaluated. There are three types of Flow of Control: • Sequential- Statements executes one after the other • Conditional- if condition satisfies, then only the statement executes • Iterative- statements execute more than once
  • 5. • if statement: Syntax: if(condition) { //statements } When condition evaluates to true then its corresponding statements are executed For example: int a=4; if(a%2==0) System.out.print(“Number is even”); It will print: Number is even as condition is true
  • 6. • if else statement Syntax: if(condition) { // statements } else{ // statements } When condition evaluates to true then its corresponding statements of if block are executed, otherwise statements of else block are executed For example: int a=7;
  • 7. if(a%2==0) System.out.print(“Number is even”); else System.out.print(“Number is odd”); It will print: Number is odd as condition evaluates to false, so else part is executed • else if statement Syntax: if(condition1) { // statements } else if(condition2){ // statements } … else if(condition-n){ // statements } else{ //statements }
  • 8. For example: int a=55; if(a>=80&&a<=100) System.out.print(“Grade A”); else if(a>=60&&a<80) System.out.print(“Grade B”); else if(a>=40&&a<60) System.out.print(“Grade C”); else System.out.print(“Grade D”); It will print: Grade C
  • 9. • switch statement: Syntax: switch(variable) //variable can be int, char, string { case value1: //statements break; case value2: //statements break; case value-n: //statements break; default: //statements }
  • 10. For example: int a=5; switch(a) { case 1: System.out.print(“Hello”); break; case 2: System.out.print(“Hi”); break; default: System.out.print(“Default”); break; } it will print: Default
  • 11. • for loop is an entry controlled loop Syntax: for(initialisation;condition;increment/decrement) { //statements } For example: for(int i=1;i<=5;i++) System.out.print(i+” “); it will print: 1 2 3 4 5 Here i is local to for loop only.
  • 12. • while loop is an entry controlled loop Syntax: while(condition) { //statements } For example: int i=1; while(i<=5) { System.out.print(i+” “); i++; } it will print: 1 2 3 4 5
  • 13. • do while loop is an exit controlled loop Syntax: do { //statements } while(condition); For example: int i=1; do { System.out.print(i+” “); i++; } while(i<=5); it will print: 1 2 3 4 5 do while will executes at least once even if the condition evaluates to false