Loop 2
Loop 2
Loop 2
Problems
for loops
break continue
a Point Reverse
Given an
Integer n Point all digits from Right
to
left
en A 3 7 26
6 2 7 3
I idea 1
N I 42 7 lastdigit N 10 2
N 26 3 48 lastdigit Nt 10 8
N 26 3 48
P s v main C
Scanner son new Scanner system.in
int n son nest Intl
f
if
neo n n t
3
N 26348
A lastdigit
while N 071 26348 X 8
int lastdigit 490109 2634 4 4
System out pointin last
digit 263 3 3
N a 6 6
105 26
3 2 2 2
berit
5 times
int i og initialization
while ie lo int
I Statement
I Statements
it
3
flow
I
1 time initialize i
theloop
gone
execute the statement
Cinta c I c S
for
3
2
b
T
4 T
t 5 T
g 6 7
Genit
y
y
Q Count factors
Given a Positive number Point all the factors
nitmbers
that number
of completelydividing
a
Ea N 12 I 23 4 6 12
N 17 8 1 17
N 24 1 2 3 4 6 8 12 24
minimum a 1
factor of
Maximum factor of a N
Hideat
N 10
1 7 AM I 10 1 0 I
2 I N 2 10 2 O W
3 I 4 3 10 3 1
4 7 NY 4 109.4 2
5 7 Ni 5 10 5 0 K
6 7 Nab 10 6 4
7 7 Ni 7 10 7 3
8 7 Ni 8 10 2
8
s g 10 9
g Ni 1
10 10 0 W
10 Ni to
I Psuedo code
P S v main C
Scanner son new Scanner system.in
int n Sen neat Intl
iteration count
Mt
i 1
if N o
int it
g
Systemoutpointer i
g N 3 91,33 Prime
N 13 L 1,133 Prime
N 30 L1 2 303 not Prime
I idea
Count the N 2 Prime
factors of
else not Prime
N 13 Count 2 Prime
of factor no
P S v main C
Scanner son new Scanner system.in
int n Sen neat Intl
int count o
inti is n itt h
for Ig
i s
if N o
a iterations
Systemontpointed count to
Count 2 4
if
System out point ln Prime
use
system out pointer not Prime
z
I Break Statement
not affangde
int i i g is S itt h I
9 for i 374 2
if break
y 3
System out pointer i
2
3
4
5
break The moment you execute break Statement
exit the current loop
you
En int i I i lo it t i icio
for I T t
0 12
Quiz 4
i 9 5
int i 71 o f
for 5,9
O
break
System out point it
g
I continue Statement
Skip and to hent iteration
go
En
i itt i i as if
for int o iss
l t
if
is 2 o
f
continue I t f
3 2 t
3 t
System out pointinli f
4 t
5
f
fGerrit
0 4
I
3
Quiz 58
i as if
i inge f
for int o ice 0 A
continue 2 A t
z f t
System out pointinli 4 t
f
5 A
f
b
A
buent
4
5
dominated
false
as if
i
for int o
is 22s
5 itt o f
f
if continue
3 I t
f
A
3
2
f
A
3 f
System out pointinli 4 t
f
5
4
f
o 6 fGerrit
I 5
2
3