Loop 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Today's agenda

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

int lastdigit 4 109


System out pointin last
digit
N a 10

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

A variable created inside loop gets deleted once the


iteration is complete
11 For loop basics

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

update the variable


Q Point numbers
from 1 to 5 using for loop

Cinta c I c S

System out pointer i


T

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

System out pointer i

int it

for inti Ig is n itt h while licia


if N i oh a
systemoutpointing

g
Systemoutpointer i

Break till 9 38 Pra


d
a Is prime e itself

Given a number n Prime Prime the


if
number is a prime number else not Prime

g N 3 91,33 Prime
N 13 L 1,133 Prime
N 30 L1 2 303 not Prime

Quiz N 1 neither Prime nor composite

I idea
Count the N 2 Prime
factors of
else not Prime

N 13 Count 2 Prime
of factor no

re do Count 4 not Prime


of factor
IIPuedo Code

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

System out pointen i 2 T 2


i 2 I break
if
g
Quiz38
i 5
int i 599 71
if
for
O
o f
i 2 break 3
f
if I t
f
system out point it 2 A
3 t
f
Genet

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy