SlideShare a Scribd company logo
1 of 15
Download to read offline
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 1/15
Operators, control statements
Operators in Java
Operator is a special symbol that tells the compiler to perform specific mathematical or logical
Operation. Java supports following lists of operators.
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Ternary or Conditional Operators
Arithme c Operators
Given table shows all the Arithmetic operator supported by Java Language. Lets suppose variable A hold
8 and B hold 3.
Operator Example (int A=8, B=3) Result
+ A+B 11
- A-B 5
* A*B 24
/ A/B 2
% A%4 0
Rela onal Operators
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 2/15
Which can be used to check the Condition, it always return true or false. Lets suppose variable Ahold 8
and B hold 3.
Operators Example (int A=8, B=3) Result
< A<B False
<= A<=10 True
> A>B True
>= A<=B False
== A== B False
!= A!=(-4) True
Logical Operator
Which can be used to combine more than one Condition?. Suppose you want to combined two
conditions A<B and B>C, then you need to use Logical Operator like (A<B) && (B>C). Here &&is
Logical Operator.
Operator Example (int A=8, B=3, C=-10) Result
&& (A<B) && (B>C) False
|| (B!=-C) || (A==B) True
! !(B<=-A) True
Truth table of Logical Operator
C1 C2 C1 && C2 C1 || C2 !C1 !C2
T T T T F F
T F F T F T
F T F T T F
F F F F T T
Assignment operators
Which can be used to assign a value to a variable. Lets suppose variable A hold 8 and B hold 3.
Operator Example (int A=8, B=3) Result
+= A+=B or A=A+B 11
-= A-=3 or A=A+3 5
*= A*=7 or A=A*7 56
/= A/=B or A=A/B 2
%= A%=5 or A=A%5 3
=a=b Value of b will be assigned to a
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 3/15
Ternary operator
If any operator is used on three operands or variable is known as ternary operator. It can be represented
with " ?: "
Decision Making Statement in Java
Decision making statement statements is also called selection statement. That is depending on the
condition block need to be executed or not which is decided by condition. If the condition is "true"
statement block will be executed, if condition is "false" then statement block will not be executed. In java
there are three types of decision making statement.
if
if-else
switch
if-then Statement
if-then is most basic statement of Decision making statement. It tells to program to execute a certain part
of code only if particular condition is true.
Syntax
if(condition)
{
Statement(s)
}
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 4/15
Example if statement
class Hello
{
int a=10;
public static void main(String[] args)
{
if(a<15)
{
System.out.println("Hello good morning!");
}
}
}
Output
Hello good morning
if-else statement
In general it can be used to execute one block of statement among two blocks, in java
language ifand else are the keyword in java.
Syntax
if(condition)
{
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 5/15
Statement(s)
}
else
{
Statement(s)
}
........
In the above syntax whenever condition is true all the if block statement are executed, remaining
statement of the program by neglecting. If the condition is false else block statement executed and
neglecting if block statements.
Example if else
import java.util.Scanner;
class Oddeven
{
public static void main(String[] args)
{
int no;
Scanner s=new Scanner(System.in);
System.out.println("Enter any number :");
no=s.nextInt();
if(no%2==0)
{
System.out.println("Even number");
}
else
{
System.out.println("Odd number");
}
}
}
Output
Enter any number : 10
Even number
Switch Statement
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 6/15
The switch statement in java language is used to execute the code from multiple conditions or case. It is
same like if else-if ladder statement.
A switch statement work with byte, short, char and int primitive data type, it also works with enumerated
types and string.
Syntax
switch(expression/variable)
{
case value:
//statements
// any number of case statements
break; //optional
default: //optional
//statements
}
Rules for apply switch statement
With switch statement use only byte, short, int, char data type (float data type is not allowed). You can
use any number of case statements within a switch. Value for a case must be same as the variable in
switch.
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 7/15
Limita ons of switch statement
Logical operators cannot be used with switch statement. For instance
Example
case k>=20: // not allowed
Example of switch case
import java.util.*;
class switchCase
{
public static void main(String arg[])
{
int ch;
System.out.println("Enter any number (1 to 7) :");
Scanner s=new Scanner(System.in);
ch=s.nextInt();
switch(ch)
{
case 1:
System.out.println("Today is Monday");
break;
case 2:
System.out.println("Today is Tuesday");
break;
case 3:
System.out.println("Today is Wednesday");
break;
case 4:
System.out.println("Today is Thursday");
break;
case 5:
System.out.println("Today is Friday");
break;
case 6:
System.out.println("Today is Saturday");
break;
case 7:
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 8/15
System.out.println("Today is Sunday");
default:
System.out.println("Only enter value 1 to 7");
}
}
}
Output
Enter any number (1 to 7) :
5
Today is Friday
Looping Statement in Java
Looping statement are the statements execute one or more statement repeatedly several number of
times. In java programming language there are three types of loops; while, for and do-while.
Why use loop ?
When you need to execute a block of code several number of times then you need to use looping
concept in Java language.
Advantage with looping statement
Reduce length of Code
Take less memory space.
Burden on the developer is reducing.
Time consuming process to execute the program is reduced.
Difference between condi onal and looping statement
Conditional statement executes only once in the program where as looping statements executes
repeatedly several number of time.
While loop
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 9/15
In while loop first check the condition if condition is true then control goes inside the loop body otherwise
goes outside of the body. while loop will be repeats in clock wise direction.
Syntax
while(condition)
{
Statement(s)
Increment / decrements (++ or --);
}
Example while loop
class whileDemo
{
public static void main(String args[])
{
int i=0;
while(i<5)
{
System.out.println(+i);
i++;
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 10/15
}
Output
0
2
3
4
for loop
for loop is a statement which allows code to be repeatedly executed. For loop contains 3 parts
Initialization, Condition and Increment or Decrements
Syntax
for ( initialization; condition; increment )
{
statement(s);
}
Initialization: This step is execute first and this is execute only once when we are entering into the
loop first time. This step is allow to declare and initialize any loop control variables.
Condition: This is next step after initialization step, if it is true, the body of the loop is executed, if it is
false then the body of the loop does not execute and flow of control goes outside of the for loop.
Increment or Decrements: After completion of Initialization and Condition steps loop body code is
executed and then Increment or Decrements steps is execute. This statement allows to update any
loop control variables.
Flow Diagram
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 11/15
Control flow of for loop
First initialize the variable
In second step check condition
In third step control goes inside loop body and execute.
At last increase the value of variable
Same process is repeat until condition not false.
Improve your looping conceptFor Loop (https://www.sitesbay.com/cprogramming/c-for-loop)
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 12/15
Display any message exactly 5 mes.
Example of for loop
class Hello
{
public static void main(String args[])
{
int i;
for (i=0: i<5; i++)
{
System.out.println("Hello Friends !");
}
}
}
Output
Hello Friends !
Hello Friends !
Hello Friends !
Hello Friends !
Hello Friends !
do-while
A do-while loop is similar to a while loop, except that a do-while loop is execute at least one time.
A do while loop is a control flow statement that executes a block of code at least once, and then
repeatedly executes the block, or not, depending on a given condition at the end of the block (in while).
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 13/15
When use do..while loop
when we need to repeat the statement block at least one time then use do-while loop. In do-while loop
post-checking process will be occur, that is after execution of the statement block condition part will be
executed.
Syntax
do
{
Statement(s)
increment/decrement (++ or --)
}while();
In below example you can see in this program i=20 and we check condition i is less than 10, that means
condition is false but do..while loop execute onec and print Hello world ! at one time.
Example do..while loop
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 14/15
class dowhileDemo
{
public static void main(String args[])
{
int i=20;
do
{
System.out.println("Hello world !");
i++;
}
while(i<10);
}
}
Output
Hello world !
Example do..while loop
class dowhileDemo
{
public static void main(String args[])
{
int i=0;
do
{
System.out.println(+i);
i++;
}
while(i<5);
}
}
Output
1
2
3
3/18/2019 Operators, control statements: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 15/15
4
5

More Related Content

What's hot

Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++Nimrita Koul
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-Mahmoud Alfarra
 
C conditional mod
C conditional modC conditional mod
C conditional modAnil Sharma
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handlingKuntal Bhowmick
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud Alfarra
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6solutionjug4
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6ashhadiqbal
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...PVS-Studio
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual BasicTushar Jain
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handlingteach4uin
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1Shinu Suresh
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universitysjskjd709707
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6comp274
 

What's hot (19)

Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-
 
C conditional mod
C conditional modC conditional mod
C conditional mod
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
Quiz5
Quiz5Quiz5
Quiz5
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
 
Ppt chapter07
Ppt chapter07Ppt chapter07
Ppt chapter07
 
Pptchapter04
Pptchapter04Pptchapter04
Pptchapter04
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Excception handling
Excception handlingExcception handling
Excception handling
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 

Similar to Operators, control statements represented in java

Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptBinu Paul
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.netsuraj pandey
 
Java PSkills Session-4 PNR.pptx
Java PSkills Session-4 PNR.pptxJava PSkills Session-4 PNR.pptx
Java PSkills Session-4 PNR.pptxssuser99ca78
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011David O'Dowd
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summaryEduardo Bergavera
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and TestingDr Sukhpal Singh Gill
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineMalik Tauqir Hasan
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Techglyphs
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingRichard Clark
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3Isham Rashik
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
 

Similar to Operators, control statements represented in java (20)

Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Java PSkills Session-4 PNR.pptx
Java PSkills Session-4 PNR.pptxJava PSkills Session-4 PNR.pptx
Java PSkills Session-4 PNR.pptx
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and Testing
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
 
Adsa u1 ver 1.0
Adsa u1 ver 1.0Adsa u1 ver 1.0
Adsa u1 ver 1.0
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 

More from TharuniDiddekunta

More from TharuniDiddekunta (17)

String class
String classString class
String class
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Packages access protection, importing packages
Packages   access protection, importing packagesPackages   access protection, importing packages
Packages access protection, importing packages
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Classes, objects, methods, constructors, this keyword in java
Classes, objects, methods, constructors, this keyword  in javaClasses, objects, methods, constructors, this keyword  in java
Classes, objects, methods, constructors, this keyword in java
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Software Metrics (Testing)
Software Metrics (Testing)Software Metrics (Testing)
Software Metrics (Testing)
 
unit 3 Design 1
unit 3 Design 1unit 3 Design 1
unit 3 Design 1
 
Unit 4 testing
Unit 4 testingUnit 4 testing
Unit 4 testing
 
risk managment and quality
risk managment and qualityrisk managment and quality
risk managment and quality
 
Design
DesignDesign
Design
 
Network layer
Network layerNetwork layer
Network layer
 
Transport layer and Application layer
Transport layer and Application layerTransport layer and Application layer
Transport layer and Application layer
 
Congection control and Internet working
Congection control and Internet workingCongection control and Internet working
Congection control and Internet working
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

Operators, control statements represented in java

  • 1. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 1/15 Operators, control statements Operators in Java Operator is a special symbol that tells the compiler to perform specific mathematical or logical Operation. Java supports following lists of operators. Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Ternary or Conditional Operators Arithme c Operators Given table shows all the Arithmetic operator supported by Java Language. Lets suppose variable A hold 8 and B hold 3. Operator Example (int A=8, B=3) Result + A+B 11 - A-B 5 * A*B 24 / A/B 2 % A%4 0 Rela onal Operators
  • 2. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 2/15 Which can be used to check the Condition, it always return true or false. Lets suppose variable Ahold 8 and B hold 3. Operators Example (int A=8, B=3) Result < A<B False <= A<=10 True > A>B True >= A<=B False == A== B False != A!=(-4) True Logical Operator Which can be used to combine more than one Condition?. Suppose you want to combined two conditions A<B and B>C, then you need to use Logical Operator like (A<B) && (B>C). Here &&is Logical Operator. Operator Example (int A=8, B=3, C=-10) Result && (A<B) && (B>C) False || (B!=-C) || (A==B) True ! !(B<=-A) True Truth table of Logical Operator C1 C2 C1 && C2 C1 || C2 !C1 !C2 T T T T F F T F F T F T F T F T T F F F F F T T Assignment operators Which can be used to assign a value to a variable. Lets suppose variable A hold 8 and B hold 3. Operator Example (int A=8, B=3) Result += A+=B or A=A+B 11 -= A-=3 or A=A+3 5 *= A*=7 or A=A*7 56 /= A/=B or A=A/B 2 %= A%=5 or A=A%5 3 =a=b Value of b will be assigned to a
  • 3. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 3/15 Ternary operator If any operator is used on three operands or variable is known as ternary operator. It can be represented with " ?: " Decision Making Statement in Java Decision making statement statements is also called selection statement. That is depending on the condition block need to be executed or not which is decided by condition. If the condition is "true" statement block will be executed, if condition is "false" then statement block will not be executed. In java there are three types of decision making statement. if if-else switch if-then Statement if-then is most basic statement of Decision making statement. It tells to program to execute a certain part of code only if particular condition is true. Syntax if(condition) { Statement(s) }
  • 4. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 4/15 Example if statement class Hello { int a=10; public static void main(String[] args) { if(a<15) { System.out.println("Hello good morning!"); } } } Output Hello good morning if-else statement In general it can be used to execute one block of statement among two blocks, in java language ifand else are the keyword in java. Syntax if(condition) {
  • 5. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 5/15 Statement(s) } else { Statement(s) } ........ In the above syntax whenever condition is true all the if block statement are executed, remaining statement of the program by neglecting. If the condition is false else block statement executed and neglecting if block statements. Example if else import java.util.Scanner; class Oddeven { public static void main(String[] args) { int no; Scanner s=new Scanner(System.in); System.out.println("Enter any number :"); no=s.nextInt(); if(no%2==0) { System.out.println("Even number"); } else { System.out.println("Odd number"); } } } Output Enter any number : 10 Even number Switch Statement
  • 6. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 6/15 The switch statement in java language is used to execute the code from multiple conditions or case. It is same like if else-if ladder statement. A switch statement work with byte, short, char and int primitive data type, it also works with enumerated types and string. Syntax switch(expression/variable) { case value: //statements // any number of case statements break; //optional default: //optional //statements } Rules for apply switch statement With switch statement use only byte, short, int, char data type (float data type is not allowed). You can use any number of case statements within a switch. Value for a case must be same as the variable in switch.
  • 7. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 7/15 Limita ons of switch statement Logical operators cannot be used with switch statement. For instance Example case k>=20: // not allowed Example of switch case import java.util.*; class switchCase { public static void main(String arg[]) { int ch; System.out.println("Enter any number (1 to 7) :"); Scanner s=new Scanner(System.in); ch=s.nextInt(); switch(ch) { case 1: System.out.println("Today is Monday"); break; case 2: System.out.println("Today is Tuesday"); break; case 3: System.out.println("Today is Wednesday"); break; case 4: System.out.println("Today is Thursday"); break; case 5: System.out.println("Today is Friday"); break; case 6: System.out.println("Today is Saturday"); break; case 7:
  • 8. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 8/15 System.out.println("Today is Sunday"); default: System.out.println("Only enter value 1 to 7"); } } } Output Enter any number (1 to 7) : 5 Today is Friday Looping Statement in Java Looping statement are the statements execute one or more statement repeatedly several number of times. In java programming language there are three types of loops; while, for and do-while. Why use loop ? When you need to execute a block of code several number of times then you need to use looping concept in Java language. Advantage with looping statement Reduce length of Code Take less memory space. Burden on the developer is reducing. Time consuming process to execute the program is reduced. Difference between condi onal and looping statement Conditional statement executes only once in the program where as looping statements executes repeatedly several number of time. While loop
  • 9. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 9/15 In while loop first check the condition if condition is true then control goes inside the loop body otherwise goes outside of the body. while loop will be repeats in clock wise direction. Syntax while(condition) { Statement(s) Increment / decrements (++ or --); } Example while loop class whileDemo { public static void main(String args[]) { int i=0; while(i<5) { System.out.println(+i); i++;
  • 10. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 10/15 } Output 0 2 3 4 for loop for loop is a statement which allows code to be repeatedly executed. For loop contains 3 parts Initialization, Condition and Increment or Decrements Syntax for ( initialization; condition; increment ) { statement(s); } Initialization: This step is execute first and this is execute only once when we are entering into the loop first time. This step is allow to declare and initialize any loop control variables. Condition: This is next step after initialization step, if it is true, the body of the loop is executed, if it is false then the body of the loop does not execute and flow of control goes outside of the for loop. Increment or Decrements: After completion of Initialization and Condition steps loop body code is executed and then Increment or Decrements steps is execute. This statement allows to update any loop control variables. Flow Diagram
  • 11. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 11/15 Control flow of for loop First initialize the variable In second step check condition In third step control goes inside loop body and execute. At last increase the value of variable Same process is repeat until condition not false. Improve your looping conceptFor Loop (https://www.sitesbay.com/cprogramming/c-for-loop)
  • 12. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 12/15 Display any message exactly 5 mes. Example of for loop class Hello { public static void main(String args[]) { int i; for (i=0: i<5; i++) { System.out.println("Hello Friends !"); } } } Output Hello Friends ! Hello Friends ! Hello Friends ! Hello Friends ! Hello Friends ! do-while A do-while loop is similar to a while loop, except that a do-while loop is execute at least one time. A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given condition at the end of the block (in while).
  • 13. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 13/15 When use do..while loop when we need to repeat the statement block at least one time then use do-while loop. In do-while loop post-checking process will be occur, that is after execution of the statement block condition part will be executed. Syntax do { Statement(s) increment/decrement (++ or --) }while(); In below example you can see in this program i=20 and we check condition i is less than 10, that means condition is false but do..while loop execute onec and print Hello world ! at one time. Example do..while loop
  • 14. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 14/15 class dowhileDemo { public static void main(String args[]) { int i=20; do { System.out.println("Hello world !"); i++; } while(i<10); } } Output Hello world ! Example do..while loop class dowhileDemo { public static void main(String args[]) { int i=0; do { System.out.println(+i); i++; } while(i<5); } } Output 1 2 3
  • 15. 3/18/2019 Operators, control statements: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/operators-control-statements?module_item_id=21012843 15/15 4 5