Operators & Control Statement in Java
Operators & Control Statement in Java
Date
Page:
a) Arithmetic Operatars
These are used for basic math operations.
Operator Example Descripion
+ atb Addition
d-b Substraion
Mutiplication
alb Diyisiom
% a%b Modulus (remainder)
@Curious-programmer
cIASSMAte
Data
Page
Exan1ple
int a =10 , b=5;
int sum =a+b; || SUm = 15
int remainder = a% b / remainder =0
b) Relational OperaBors
Ihese operators coTmpare values to see if they are
equal Qreater or smaller than
than each other.
Example
if (azb) {
printf ("a is greater than b");
@urious --programimer
cIASSMAte
Date :
Page:
9 Logical Operalors :
Example
if (a>0) &R b<10)
| |Executs if both condiioms are true
OCurious -programmer
cIASSMAte
Date :
Page:
d) Bitwise Operators
These wonk with the binary fornn f rumbers (bits)
and perform operatiorns indivicual bits.
Example
int result a&bi | bituise and a andb
@ Curious -programmer
cIASSMAte
Date :
Page:
e) Assignment Operators
These are used to assion a value to a variable
Evample
int a=5;
t3 ; Il a= 8
O urious - programmer
clASSMAte
Date:
Page:
)Miscellaneous Operalors
These are special operators used or speciftc
tasks.
Exanmple
int max (a>b) ?a:b ;
Il max = a it a>b , else max =b
@rious-programmer
if aciom twotrue,
decice
program only
cIASSMAte
repeat between
code is
perform Conditian
:DatePage:
Or ") choose @
urious
-progra
oa b
conditioms
your
help
nents block than
to youthe
Statements greater conditim
isnet
want letsif
statements statement
runs talse.
true.
is yoL statemert
Statementone
Flow based :statement ("a when : it's
sta actions. is S
printf code
b)
Comtrollouwdo conditiom
Eanaple: isIH a
used ifonly -elseif-else
if
to (a of ane
me
Cortrol if ifThe
whatcertaina)
if if blocks
2 and
b) The
to handle options
@
urious--programmer
cIASSMAte acioms me
to checking i breaki
break different
:DatePage:
parallel way ")i
Qreatera");
b');
than ")i");
day
cleaner
than by options
many
against ("Monday
Tuesday
nvalid manychoices
two
Conditians
Qreater Conditioms. hae
are (" ("
is printf menu
there printF
printf
) statemert
Switch
Stotement you
printfis
("a
is possible when1ike
when : :
(day)
Switch
("b 1 2 default for,
Casecase
if elseprintf
Exanmple
: (a>b) usedbased
take Suitch used
multiple
yariable check
is is
3
It The IH to
cIASSMAte
Date
Page:
3 Loops
Loops are used to repeat a set of actions multiple
times, like running a task over and Over
umtil condiion charnges
a) for LOop
A for loop is used when you know how many.
times you want o repeat action
Example
for (int i=0: ii<5i
i+)
printf ("%d"ili /Prints 01234
Examples
int i 0i
while (i<5)
print+ "%d", i)i Prints 0011 23 4
1++j
3
) do-while Loop:
A do-while loop is similar toa while loop ,
but it always runs at least OMce betore
checkinghe condition
int i =0j
do
printf ("%d",i);
1++j
3 while (i<5) ;
urious -programmer
programme @uriLS
next the nmoves and
Toop
me.
on current heskips stament continue Ihe
Continue: b)
finishes. itbefore
fo p astop towant you when break Use
is wheni Ioop the SBops break (is=5) if
;itt) j=0ii<
10 Cint tor
Exarmple:
progranm
opart fhe to n moves
and
ompletelyfhe 1op the next stopsstatenernt
statoment break Jhe
breok a)
SiaBermernt continue and break 4: 4
:
conditian. the checking before
showing like once least atruns
menu
code the ensuYe towant you when used IA's
Page:
Date:
cIASSMAte
cIASSMAte
Date :
Page:
Example
tor (int i= 0; 1<10; 1++)
if (i==5) continue ; lskips prinHing 5
printt ("%d" i) 5
I/ Print 012 3 4 6 789
3
@ urious - programmer