

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The java code for implementing a linear search algorithm. The algorithm searches for an element in an array by iterating through each element from the beginning until the desired element is found or the end of the array is reached.
What you will learn
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Pnoctical No.
Oatc G 22
Aim VWiHe o pognom for Lineon 5conch
5o1twaoe tauiced Tova Online Compilen
Poognom Code
Public closs Lineonseonchi
public StotHcnt^ lineanstanch^ (int^ onra
yC1,nx
int n Onraj.length
fon Cin iO, i<n, i++)
F ConnayC1 ) petunn
3 netunn-1, 3 Public static void main5tning ang sC3)
Tn onna yL1 f2, 4,0, 9, int x 1, int nesult linean 5eanch (onnaj x fCoesult =-1) Sjstem.out.pnintlo C"Elemenl nol found'") else Sy5tem.out.printlh Eleme nd found at idex: psoH),
Output Elemen+ou nd ot index: 3 e
Conctusion: Linean (^) 5canch is (^) ave simple 5eaeehing a40nih m.T cycles +hmough he elemenls unHl+he 9utyis aund.
clASSMAte Page
Aim Woite a pnoqnam fon linear 5eanch.
so-tuoaee Nequined Java Online CAmpilen heon incan 6eaech is a5equenfio lseandhing
alaaiaithm wheme westant rom one end and check evceny elemeq offhe lisl un he desiol
elemraE is fauad
Alganinm sbepiTnavense he amnay 54p Mateb he keyelemeat uith anayee
inde x posiHor 4t heenm element slkpAI£ kyelemendt is not ound,ndunA- Pnoqaam Cocde
puble class Linean Seanch i
iatnEaoma leng
neunn i DeHino-1,
2in annayI1e 2, 4,01,9t
iat x =
ot aesult= ineanseanCh (anay x
else
conclu6 (^) iom (^) Linean (^) seanch (^) 1S a veoy (^) simple (^) seanching (^) ayordho- t cycles throough the elements untIthe gueny 15foundh