0% found this document useful (0 votes)
20 views32 pages

AD 1 Assignment

Ad 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views32 pages

AD 1 Assignment

Ad 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
AA ssignrneuk 0 Find the sum st 1 numbers €f an array: import java.util. * ; public class Q17 public static vord matn C Stoingl] ages 4 Searhor ses mew Sannoe Coy stem hy) 5 - System cu. print C" Enter the mumbo of elemauks in al anion int ms semext Tmt} int ony LJ = new int (n]5 Sy stom. out prinths (* as ehemouts 115 for Cint (=a; Can tary Li] = se Mente Tres for Cink C20; 6 avrlength 5c) F sum 4 = on Cid; System-ouk.printin (The sum of the elemanks 16 pa sum); 3 3 OvTPOT: Emtern the srunbur of elem Tr ow annoy: 3. Emtec tHe atin. elem 2 2. Te sum ofthe clammy is an: Find the maximum elements tr aw anton, Import Jona - fil * 5 public ctass G2 § public static void moin ( String U] ange) Scanner se =mnew Scanner (System. in); System. oud print C" Enter, tha mo. Sf elements !')5 int m= se-nextTmtd)5 int CJ = mew int (ys System, uk: printin CS entud the clernsads 1 |); for Cint (20; tan; tg amvay LID = Se. maxt Tat O15 3 Int omin wowy CoD} int max = eoy Co: PAL System out. prantin Co The min, element anim J 5 | gym. out. prtatin CY Ta moat. element oo) 3 OVTPUTI— Emtex the numbs of elements . 4 Ent the elements: 1 3 68 The min. Element 1 The max. clemat 28, 3. WAP to vrtede an arnoy by K position. import java. abil Seannun} public class QBS public. stakic void main (Shivg CI ange) $ Stannsr sc = mew Scanner (System. )5 System. ouk. prin€(" Ente tha nf clemarcs t") 5 imt m= sovhevt nt); int CJ agkay s new int Cn]; font (205 ign tery g carro CIT = geenent dnt O15 Baten out pant! ator Aa ruumber of postions to rotate 1") ) int Ko gemext Tat} rotate Array Corso , D3 System ouk. prmtin CS Tee rotated ory iss; for Cint Uz array) { System out print Cit"); peblle stakie votd rotate Aveo Cnt CJ vowy int «) + int m= onnay ~ Aang Kr kyn reverse Grevouy Canney, 0,77!) 5 reverse Crecay Conroy, 2, K-15, a tires | eed | Ke j public ec Noth reverse Brecon Cint Ld svoy int sto, uabile (stot < end) { Int temp sasuay [stood |; asvray [steak] = avray Land] 5 array [end] c temps cto tt 5 end -- 5 i 3 SOTPUT!— Ent ino ef sles Entex tha eclemay : 1 2 3. Emin the no. &f positon to rotate 22 The voloked arry iss 2 a. int end )F » Ankan Dhar © 2341004233 Ass laren ate fe Find the Largest sum conti gous Suloavny + D public class af public static int Jasgest sur - tombs gous — Sub int max. ending hue = 05 int may - so- fax = 05 for Cint i= 0; Uc ank.length 5 teh may -ending. hero = mast -ending - hare + ae Ce] 5 Uf Coase ending. hers <0) 7 ahrasy Cint on ca){ max. ending. hare = 05 1 (omox-endivg hare 2 Gx. so-for) { | moxt-co-fax= marZending- hare 5 | 4 ; : wretwu max-so- fox : 4 public stokie veid main C Sting C] ongs) f imt ove CT = 41,2, n4 335 int cresulk = largest sum conbigous subarnay Carre); | | System. cub. printin Coresult)5 ‘ 3 ovteet— 5 2.) write code de find | avwy. : D public class Smallest Positives } public stodic int smalkest Cint art) { Ime m= ane Lengths for Cnt t= 03; ten; cat) F tohite Cali) >0 K& OACIT <= nN && aur Laxxce] -1 = ACO DE smallest positive omissing vember frou, Prt fomp = dor Loe td — 11; et Com(id-1} be verily oun Cb] = tenp; oe ? a ) wv @ a dow Cint C20; Com steady rf Com Cid} i+ ©) § vrelinn ith 5 7 - oediwan M445 3 5 public stake veid-maln Ctvng angel) { Tmt ou C] = (-4,t, 4,6}; System. out: printin Csmattart Cae) J; 5 OvTPUT I= wewoeewreermfFreFrewr ef 3. Write a java program ito amtarge clement of the to étore rmoximurs, minim, second maximum ,eecond minimman and $0 On. Csorted array). | public class MayMin Array { public stake void anange Cot oe C1) £ | InE M = or. length 5 int ofxC] = neo int [1]; for Cink T=05 Cem; cet) £ : aux Ci] = wae ) int stoxt = 05 mE step = n-1 5 for Cint (s03 Cems C444 ) Y Cina. coy§ ' ou Ci] = aux [Stop]; Step = step-~15 5 che § ar (CJ = aux Cs tock] Stonk = stat +135 3 for Cint isos temsteny g System .ouk- print Com Cid ©); Syston ouk. prints C15 | Sante stoic void main (She ovgs (1) F ant oo C2 4 28H EATS arrange Cords | 3 | 3 JovteuT= Vib 25 34. = “ Wnite a fava code to find factorial of a rumber D) public clam factmal-findig f public static int factortak Cink ~) f imt wesulk = 45 dor (int C=13 form, tet) { result M2 75 % crest vet results t public statie werd man CSthioy ongs tif | (nt murder = 5; f Cramer 20) f System out. printhe (fouorial (mentor) ; Bee Se exiathn(* fainted of ve me 8c Sy stern. out: prin O ws atie’, 3 j outpuT:~ 120 pe FB) Write a jaw program te gowete the mith Gbonacti rumber > public class Fibomactifinair < public stedic long fibonacei Cnt TE (m==4) cratinuy 05 ‘ | TH tms=2) | vedtitan 5 Log as 05 tora be 45 ; Lang filoo= 05 _ | fore (Int 1235 (emer) § fibo sath} , | a= by ‘ 3 lo = fibos y relives fibo : | pulolie stoke Void mam CString ong TI) | mt n= 53 bo fF (neod$ ’ Sapstern out printin (SS Numborrmast be AVE "ys » J de § ’ System. oud. paint (bona cu) j)¥ ‘ 3 3 » ) OUTPUT:~ \20 Anteon Dhak, 2204233 4 moment ~ 3 Wnite a program to find the sum of tnt numbers. import jaro veitil. 5 pubtic cloyr sum J pubic stake void mam (String Clare ) f Scanian se= Mew Starner (Syston) {| System. out. printin (% Enter rw of elemorks 1") 5 int mz ge neetInt O15 int sum =05 System. out .printin C Gator mumbo") 5 for Cnt to; tens CHADS mt num = ge. next Os sum ts mum 5 I System ouk. printin (gum <4 Sum’) 5 3 3 OUTPUTS Enter mo. Sf elemants + 3 Grow rumbou! 1 Sum) 6. Write a program to find moximnum ond minimum, import Jawa. Chaat; public class aminmax { publle stodia vets main Ching CT args ) { Stannen se= new Seannor C System. in), System, out . printin (" Enlor total no") int me se.ment nt (75 mt may = Sntegar. MIN ALUB; mt min = Tmleqat. MAX-V ALE 5 System.euk. (rinthn CY enfoe wo 1"); . for Cint S205 Cony Let) £ int mum ge. next Ent Ors Tf Cwm Samay) nay = uum 3 1£ Crum mewn Seannur C System vin) 5 | System: oud printin C" Ente no 1) | int ms seme ently ; ’ | Syste oul. print (" bon ace Number!” + fibomacci Cn)) 3 5 | public stoic Pit Ptbomace’ Cnt ») { if Cners)§ vetuu 1! Jee sue fibonacci(m-4) 4 fibe nacci (m-2); 3 3 | ourput, enterno: 8 | Cibonacel wooded: 2. 5, White oa program fo find the GOP. =) ienport jowa util oy pubic clas ASOS FT public static veid maim (simvy [J ong) t Scanne se = mew Seannex C syston Ys Oysten out. prartn (" Ontox too m2.+ Di Int 06 = ferment dnt (0; int yo = ge. mext fork ged Cry) 5 System oud primtttn Ch Gen ty) f 3 wibtic static wt ged (tnt % | if Cysr0d { rete 963 Seve cetun ged Cy, WAY) 5 3 3 | evTPLT! Enter too no. +40 20 | GCP s to. : 6.) White a program te convent clectmal to Nnexaclecimal + =) import Jawa. util. 5 | public class 43964 public stodie verd motnC sting CI ange) 4 | Seon cer mew Seannee CSy stems in) 5 | System. cut -printhe ("yc a deerme sy; Int mum = So-mextInt OC); String rresull = uum 220? "0": deaToHex Crum); | System aut printin (“Ktexace cenal |" cregutt) 5 pubtic atatic shang decToHae Cintn) ¢ f Cmeco)$ | wet ruth, | ele Int verre ley | nor hey 2 (vem <10) 2 Cobar) (remy ‘ey, 5 Coren) Crem ota). 3 rehann dee Totten Cr{te) t+ hex) ' q 3 ie enter a 19 devia t 12 Hlemadecinak tC a cone & program ty compute nth power of aA mumber.. SD] fmport jowarcihil. «3 publee class ASQa ¢ Public stedie void main Cshing (1 G4) { Sconnx 6¢ = mew Scanner CSy stem); System. oud. printhr C" Chix base"); mt base = So-mevtInt C95 System. ot. prittin C" Ante @xponents'' J; Int exp = ge .mextint C1; System, ouk prantin ("Result 1" + Power Cbase,e) § t priblie stotve double Power (int bose, mt) § Uf (erp ==0) f rvetivn 1} JFebe Felunn base F Pewert (lease, axp-t) 3 3 3 ovTpuT!: Entex bose! 10 En for 2yponend + Resutt } 1000 Waite a program to find arnallest positive mmessing murrber, public claw Acae $ public static void main ( Shing Cy args int ou (] = 214,-1,0,3, 2,-4 35 int Smatlest Porttive = find positive Caty0, MAX. VALOE) + Lf Com altest positve 2 = Sorter. MA VALU) System eut.pwint C" Not Found"; Systom.oud print C° gmathest Positive infeqae Ht Ge allest pai) 3 public stake irl find Smallest Cant CJ are) $(int ewamst ~-D) ; Tf Qndex s = over. length ) £ aebin coovmuk nin 5 3 cbse 4 « cava Murr 2 cud Lindex] ; 5 tune find gmokst Cvsy trdesct{ , evant min)s 1 | 3 \3 | OvtTPUT: Smallest Positive tegen SD ANICAN DH AR 2341042 33 ‘| Noite a program to sot the elements Sf am woes “ANF bubble sowt . DS] publle class ASHH14 public stake void mam CStving CI age) { Int oom CJ = $19,12,92,4F, iw Cint P20; (Cara tergths iet>- foe imps aeghh ovr. lengths itt) F TF Cour CT > ver Citr] f int emp = asec Ci 15 oe Cj] = Chad; ove Ly4t] = temps 5 3 for Cit P20 5 16 wur-lengths itt) f | System gut. print Caro CIT) t" "95 | 3% x 3 ovutTpoT: 4 12 (5 22. 2) While a program fo covt the clement of an arnay using Trgekhon Sort. =D public class Asya2 4 public state verd mata CStivg CI ovgs) f (nt ove = § 23,1, 10, 4ots for Cint f=0 y Agee ; fete Int key 5 ovr C675 Mt ys e-1y tshile (j>0 Fe an Ci] key VF (Sts ome CU] 5 dinars 3 an Citl]= key ; for Cint t20, cane tengtys Cat g System out. print Cos CC] 5"); 3 3 lourpu Ts al Waite a program fo sext the clement Of am annoy Using | sgelecton sont, 7 public class ASHQ3 4 | public static void mam ( Shing CJ aga) f | Int we CJ = f60, 24, 104, 3 }5 | for Cint C205 Ee asc length; Ce4) f int min trex fs 1 10 23 te. -fow (int p= Ctr; JCosee. lengths set) f Hho t/min_ index = Sb 3 3 int temp = aver CIT; we Li] = tee Pmenind tx ]5 due Comin inden Js temp} for Cit (zo, Ce cue lengthy bet) § System. out. print’ Coun C1]) 5 3 Arlen Dh PBYIOY3 Assignment - 5 Write a program ste credunee Lua + import Jawa. util. *5 public class Ass5Q1 4 public static void matin ( Sting hY ays) j int wc = [ 3,%,49, 19,224 tne am = ave Length 5 rednce CE ove [01,™) 5 Systers ouch print Corus) 5 public stable vord weduce int aw CT, Pt 9) f int size 5 int index; int count= 05 for int iz0y tomy dad f Tf Conecil>o) 4 Cc onli] -7 3 ff commcée]= +0) inden ty 5 for Cint too; tem; i407 if Caw Cid 220)4 countats fF Ceount => size) f sretinun ; reduce Carr, ort Cindex]) 5 -OOTPUT: [9,0,0,0,01 a.| Waite a prego to mmege fur sorted aay. 2 | import Jawa util. #5 public class Ass5Q2 fj public. static void main ( Gringl') ange) § int onl] = {1,3,18, 293; imk oomtlL = §8,6,19, 28} 5 tnt amin = Math min (Cormetength , rut Aang He) 5 | ™MeGe CARH, otk 1, min) 5 | hstem, ouk- prints (0001) 5 System. out. printh Comedy; public stake void rmege Cintawll , frrt osued, jnt win) f for (int Taos id min , it) £ t Ci] > act fo}) ¥ mt temp = are Cu] owe Cid som 1 Lov; awd[o] = temp 5 % Cae fo} > amet (1) f Ort. sort (ovr): i | ? OUTPUT: [1,3,6,.8] Cia jie, 28,29), a 4 - —___ _ ee 3.) Waite a _ program to cheek_rrewonse + BOI) Import Java. util 5 , Public. class assg34 : public stakie void main CString C1 vgs) f Int osc OJ = 13, 5,7, 12, 10, 14,1635 > 3 Systm souk. prinths Crewy Cau) 5 > public. ctokic bodsherraina vey Cink orl) f > int stot = 05 while Cstert Come leythL 22 aerc(stot] <= - asucferot +1]) f stoktr 5 F fF (stort == atlangth- £7 F : wretwar trey$ mnt end = oclength 15 > while Cernrol PO BE cvreCand] > = ar Lerol-1] § » | end =—- 5 39 . | ecer Com, stort , . for Cint ino; Kavedength dy Ot G TH Cow Ciy > vo CoH F ; vetiun falues FF public static verd wey C int we (I, int stadt, end) { : stile Copa < entry? ; int demp arn Cétort’]3 : ete [otont J = one Lonel; ee Lond J 2 temps otek try end n 3 | 3 3 4 ouTeuT. sprue. UN Orlow DLA D344 153 Assignment -6 Waite a programs to cle Limean search without wring wreemusion . public class AbQ14 public static veid main CString Cc args) 4 int C1] wre $5,3,7,1,4995 int t=95 > if Crests ~ 40g System-oud- \ olse § System.ouk prinths ("Not found "); | | | | | mt wes = Linear Search | fathn (“ Not found ") 5 | 3 | 3 public stake int LinearSeareh Cint au C1, Int t) f | for (int ooo) Tf Com fil ss retWwor 5 ie | 3 veto ~1 5 OUTPUT: Index) 2 2 write a Program to do Linea xeordy waing PreEWton , VP Public clay AGS2L public state veid main (string CT ange) § int an( Y= (5,3,9,1,9F5 int © = 35 Mt ves = Linear Search Cover, t) 9) 3 Uf Cres Le ot) 4 System. ouk: privitin ("Index "4 ves) 5 Sele § Sastry oul: printhn (Wnot Found") 5 "4 int public helt, bak Tien SeaeCink ote Cs re index) § if Cindex >= amr-length) { return - 35 | else if (index ==) § | rrebwor index 5 | 3 | recuvur Sinan search Cort, t ,inalen + 1)3 OUTPUT: Index tL Fon 3. Write a program to do binary gencdy witho using | recanaiom => pulolic class ALG | public stoke A maoin CString OF ongs A = F537 9,9F5 a 4s = feinatey sears Cou t) 3 | int ‘wes VE Cores Le SDE ; System. out + gantin Ci dndent" are) else . : Snes ouk: prone C8 Hot Found "D5 | y | 3 public stodie ree Cint ove C1 int 4) f int Let = 04 (KC right = ee lexagthy = 85 Uetile Clee <2 eget) £ Tmt awd = Lake + Coeghé debO)/ 25 Uf Comm Cmid] = >t 4 vcoturun rid 5 FEL Core Cid S47 § Jekt= wid A 1 5 Gake § | 3 ight = wid- 15 | ovtPeT: Index! 3 4 Write oo Provan tho do binary Seo wsiong ereeuHstor | method « | Public class AGBUT public static ved anain CSoimg tS ass) § me wer l= ¢ Sita Sets | | | mt t= 95 | int wes = brary Seareh Corr, (0) 3 | f Cress -4) f System. out. printhn (Imes |" + ores); | Jeter § | Sy stam out prnths C" Not Found") 5 3 % | public stedie mt bmary search Cint sol] jit t mt Uebt rg) f TE Chebt Y right) Swetwur - 105 F | Ant mid = dehb* Cright — Lege) /2 5 | TE Come Comid Js rt) f | wren mids 3 TE Com Grid 1 mew Scanner C Syst 7) & 5 | System. out. print ("entur the sie of tne one | int m= semextImt dds Int CJwu = mew int Cm) 5 nds | System. out print (“ent the clernents Of the annoy | fore (int t= 03 Cem y ttt) | coc Li] = Seonext Tat OS < finel first vepeabed (rs) j Gooked Ved co. f ole vouk ane wopeatad clernent s+ firctepectad Ase $ , Sy stem. ouk: printh ("Mo wre peated clemangs found" )5 4 Vette elalic. int Findfind Eopeatel Got 1 on) F | for Cint 1203 ic ae tengths tT) ¢ | for (int p= Cary) sae tecgts 5ST | If (ann Pe] es arr CIE rrebwnr avoe CiT5 Ser etiwnns = 15 | 3 j Oukpet! Fader the size OF the assy: G Enter the elements | 10 20 20 Yo So 60. first repeated clement +20 2] Pint duplicate in a sist . =) | import Jowa til, + 5 iraport aura. uti « Arvvoyjlist 5 import Jowa, etal. Uist 5 Public clam print Duplicites public ctedie vet main (String C] evga) 4 Stannsk Sc = Neo Seanne Csystern.ty) 3 System oud print (" Crtuc He size "); int n= ce. madttut C15 | ink CY osu, = mec int Cn] 5 System suk. pravtiy OC erfos the elements") ; for Cnt iso, Con, tH) f eset [i] = oe. roxt Gat J Uist integer 7 dup cabs = find Dupli calesCoarseory)s UF CLeptteaten «jx Ernphyor) 4 | System cut fomithy C' Duplicate olarrants 3" chuplicakes J Jeet System. 68. prinitin (We oluplicabi clement s found”) 5, 3 5 public stoic List Ctnkger? find Duplicatis Cont CJ aru) f | List (10,207, eer, r——r eS 3] import fart neO sne public class FndMissing Number { vf Public stakie void aman (Shing TD ange \ Beannsr

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