Aoop Practical 4
Aoop Practical 4
Java 210ooBos2s
1 You ave qiven an away iot lategersS. Nou, fuoO Funduons FlrJ arnd G[l are deined
: Tis e ralleer numbeY 2 Such Tkc XTEN and A] 2ACZI
GKThis isthe Smalest Nuwmbey Z such trod kL 24N and Alx > AE
Nouy you need to nd ov each inderi ot s aray GEO) where ieiLN. LA auuh a
Ambr does hot ewity toV a particular inde i, oudtp ur 1 as ifs ansuer-1fsuch a anher
HG)
newtiae Ci) --1)
oppend]
else
sbapend0-.)append "),
o
Ouwtpuur
H 4 12 -I-I
2. Teuver of Henei is a maihemahical puzzle twhare we kave hvee rods ond o desks. The objecive a
he puzele is to move e enhive Stack to onomer ro dy 6bepng the tbllowirq smple rule8
o stak.
ifCo--o)
return
Oukpuh
dick 1 meved
trom to C
mbved rom A to B.
dic k 2
Jn-Lab
).Wite a Java Pregrom to onvert cund
evaluate Simple pasttix expressions uSing a Stodk.
Case '
stack push (veul 2- vouli ),
bveak
Co&e
impart jaaruhl *
ouuput H
3. publc coss Soution f
public 1t Gemplefe Civct ( tCI gos int q est
int Corv Rernanung
tnt fotou Renrodrurg -6
int stayt z0)
for Gint i-o feqas. lergthi itt){
int reairiny= qas i]-Co St 1;
ifCcon Remaini g eo) f
start-i
CorrRemoirinq remarirg
else
Co Remoinirq t Remounirg Output: 3
46tad Remainng t:
rerodnlq
f Cbtal Rervaining a o)
vetun;
else
veturn clayts
Past-Lab
) import java util. *
dass Tes+ Class
nt resulte o
yesulttt
eles
ay remove);
yo dd Cront)
yesult tt
viven aStinq S of parentheges "ov. The task is to ind a minmum num ber of povantikses
2
anlledS stivg i vald.
T'or a t ay pesitions we must add to youke o resutBrg
bxample
relurr od fn;
one c