SlideShare a Scribd company logo
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

More Related Content

PPTX
Control Flow Statements
PPTX
Control statements in c
PDF
Unit ii chapter 1 operator and expressions in c
PPT
Types of c operators ppt
PPTX
Conditional Control in MATLAB Scripts
PPTX
COM1407: Program Control Structures – Repetition and Loops
PPTX
Operators and expressions in c language
Control Flow Statements
Control statements in c
Unit ii chapter 1 operator and expressions in c
Types of c operators ppt
Conditional Control in MATLAB Scripts
COM1407: Program Control Structures – Repetition and Loops
Operators and expressions in c language

What's hot (20)

PPTX
Control and conditional statements
PDF
Programming for Problem Solving
PPTX
Java if else condition - powerpoint persentation
PDF
175035 cse lab-03
PPT
Decision Making and Branching in C
PPTX
Decision making statements in C programming
PPTX
Decision making and branching in c programming
PPTX
Dti2143 chap 4 control statement part 2
PDF
C programming decision making
PPT
6 operators-in-c
PPTX
Operators in C Programming
PPT
Operators in c language
PPTX
C Programming: Control Structure
PPTX
Introduction to Selection control structures in C++
PDF
Operators in c programming
PPT
Control statements in java programmng
PPTX
C OPERATOR
PDF
Types of Operators in C
PPTX
C decision making and looping.
PPTX
COM1407: C Operators
Control and conditional statements
Programming for Problem Solving
Java if else condition - powerpoint persentation
175035 cse lab-03
Decision Making and Branching in C
Decision making statements in C programming
Decision making and branching in c programming
Dti2143 chap 4 control statement part 2
C programming decision making
6 operators-in-c
Operators in C Programming
Operators in c language
C Programming: Control Structure
Introduction to Selection control structures in C++
Operators in c programming
Control statements in java programmng
C OPERATOR
Types of Operators in C
C decision making and looping.
COM1407: C Operators
Ad

Viewers also liked (20)

PDF
Learn Java Part 4
PDF
PDF
Learn Java Part 8
PDF
Learn Java Part 6
PDF
Learn Java Part 11
PDF
Learn Java Part 9
PDF
Learn Java Part 7
PDF
Learn Java Part 10
PDF
Defing locations in Oracle Apps
PDF
Assigning role AME_BUS_ANALYST
PDF
Creating business group in oracle apps
PDF
Learn Java Part 1
PDF
Learn Java Part 2
PDF
java.io - streams and files
PPT
Taking User Input in Java
PDF
Java lesson khmer
PPT
ppt on scanner class
PPTX
Introduction to Jquery
PDF
Java Course 8: I/O, Files and Streams
PDF
Learn Java Part 4
Learn Java Part 8
Learn Java Part 6
Learn Java Part 11
Learn Java Part 9
Learn Java Part 7
Learn Java Part 10
Defing locations in Oracle Apps
Assigning role AME_BUS_ANALYST
Creating business group in oracle apps
Learn Java Part 1
Learn Java Part 2
java.io - streams and files
Taking User Input in Java
Java lesson khmer
ppt on scanner class
Introduction to Jquery
Java Course 8: I/O, Files and Streams
Ad

Similar to Learn Java Part 5 (20)

PPT
Control statements
PPTX
Pj01 5-exceution control flow
PPTX
Control structures
PPT
Control statements
PPTX
Control statements in java
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
PPTX
control statements
PDF
Control flow statements in java web applications
PDF
Loops and conditional statements
PDF
java notes.pdf
PPTX
Java chapter 3
PPTX
Control structures in java
PPTX
JPC#8 Introduction to Java Programming
PPTX
130706266060138191
PPTX
Flow of control by deepak lakhlan
PPTX
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
PDF
Programming in Java: Control Flow
PPT
Selection Control Structures
PPT
Chapter 1 nested control structures
PDF
Java input Scanner
Control statements
Pj01 5-exceution control flow
Control structures
Control statements
Control statements in java
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
control statements
Control flow statements in java web applications
Loops and conditional statements
java notes.pdf
Java chapter 3
Control structures in java
JPC#8 Introduction to Java Programming
130706266060138191
Flow of control by deepak lakhlan
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
Programming in Java: Control Flow
Selection Control Structures
Chapter 1 nested control structures
Java input Scanner

More from Gurpreet singh (19)

PDF
Oracle Fusion REST APIs with Get Invoice API example
PDF
PL/SQL for Beginners - PL/SQL Tutorial 1
PDF
Creating ESS Jobs for Oracle Fusion BIP Reports
PDF
Introduction to Oracle Fusion BIP Reporting
PDF
Why Messaging system?
PDF
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
PPTX
Oracle Application Developmenr Framework
PDF
Java Servlet part 3
PDF
Oracle advanced queuing
PDF
Oracle SQL Part 3
PDF
Oracle SQL Part 2
PDF
Oracle SQL Part1
PDF
Generics and collections in Java
PDF
IO Streams, Serialization, de-serialization, autoboxing
PDF
Java Servlets Part 2
PDF
Introduction to Data Flow Diagram (DFD)
PDF
Ingenium test(Exam Management System) Project Presentation (Full)
PDF
Computer Graphics Notes
PDF
Learn Java Part 11
Oracle Fusion REST APIs with Get Invoice API example
PL/SQL for Beginners - PL/SQL Tutorial 1
Creating ESS Jobs for Oracle Fusion BIP Reports
Introduction to Oracle Fusion BIP Reporting
Why Messaging system?
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Oracle Application Developmenr Framework
Java Servlet part 3
Oracle advanced queuing
Oracle SQL Part 3
Oracle SQL Part 2
Oracle SQL Part1
Generics and collections in Java
IO Streams, Serialization, de-serialization, autoboxing
Java Servlets Part 2
Introduction to Data Flow Diagram (DFD)
Ingenium test(Exam Management System) Project Presentation (Full)
Computer Graphics Notes
Learn Java Part 11

Recently uploaded (20)

PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Well-logging-methods_new................
PPTX
web development for engineering and engineering
PPTX
additive manufacturing of ss316l using mig welding
PPT
Project quality management in manufacturing
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
composite construction of structures.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
Internet of Things (IOT) - A guide to understanding
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions
Strings in CPP - Strings in C++ are sequences of characters used to store and...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CH1 Production IntroductoryConcepts.pptx
Lecture Notes Electrical Wiring System Components
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Well-logging-methods_new................
web development for engineering and engineering
additive manufacturing of ss316l using mig welding
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
composite construction of structures.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
OOP with Java - Java Introduction (Basics)

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