0% found this document useful (0 votes)
0 views13 pages

OOP_Exp02

The document outlines various programming tasks related to arrays and strings in Java, including operations like checking for odd numbers in a matrix, finding minimum elements, and removing duplicates. It also covers methods for counting vowels and consonants, validating passwords, and finding common prefixes between strings. Overall, it serves as a practical guide for understanding array manipulation and string operations in Java programming.

Uploaded by

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

OOP_Exp02

The document outlines various programming tasks related to arrays and strings in Java, including operations like checking for odd numbers in a matrix, finding minimum elements, and removing duplicates. It also covers methods for counting vowels and consonants, validating passwords, and finding common prefixes between strings. Overall, it serves as a practical guide for understanding array manipulation and string operations in Java programming.

Uploaded by

heetkarena123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

* Expeximent NO: 2 *

AIM To Len
Aays and Strings in Tala.
Paactical questons

1 Wecite oomthet gen te 66 tordimensiona


mat'ix fined nith o's and is dig lay +he metaix,
Check evey San and Col21mn hove an odd numbe's

Publiccictss Matixche ckex


Public Stedic Void main( String LI arqs) i
int LJCJ mats, ix nen int l6J[6I;

I/ make evey Aow and (olmn feve cdd num bes's ok 1's,
fox (int i-o;i<6itt)i

else

6*6 MetLIK
to6( int i=0 i<6 ; +t)
fox (int /=o;jk6ijtt)
visioN Systen Out. [9int ( mettix [iTLJ7);
110111
101 111
1 11 0 1 1
11 101 1
O111
1 1
(tPð.
1) >
visioN
6oi nin
it kegth Ci7. a y j<i=0; Cint fox
itt)i i=o;l<orey
kerg;th int tos(
minCol=
osayto1To]; Element min t
(1+] Resut ("indices
(' ; fginttnSystem.cut
CoT);
:estut erement "Minimum .tut.fhintr Syctem
ayi lemantfindMinE Resutta CJint
displaymin.
Element Fmd
& I
mtLIL]
mein void Stedic Prubeic
MinElenmentE
indes class ublio
ardiramu ensionad tO aindices
in thei and
(ements minimum the
ctusens thet method qeneriC. 2)Witea
Plintn; ovdSyst, em
eetusn me int(UfninElement minß0À ninCot :

3.) Weite a method thect Cturns new

elimincting -the
import
dupliccte Values
ala .1til.. Hash Set:
in the fay.

Rublic class Duplicate Eleminetoh


hubtic Static Void main(String Ll args)
ntt] aut =I,3,2,4,2, 5,3',4 :
Hash Se+< rntsqes> hs= nen Hash Set <>N
foA(int l-o; ikart.fergth ;itt)
hs. addar ti3);
3
forCint mum: hs)
System .0t.print(num t

impost java.util. Scannes


Public sietic Void main( String L7: 69s)
Seannes Se = mea scennez(Systen. in);
System.bLt. Phinttn( Ente elements for Aray I;
visioN

) OLPut, 2)
Minimum element : 1
tndices: (2, 1)

0etput. 3)

1 23 45
System. 0uh. Peintan ErHek elenst fer Aray 2:

| choose cpesat icn


Sy stem.out. peintln Choose ofo iog C+-,*): ;
Chag oRetion = SC. nentt.cheAt (b):

PesKOh m oreation and display jresult


int I] esult = reulpam Opoustiön (orry1, antey 2
Otesut 'on:
System.cut.fsintLn("Resuit :"

Beivecte Static int tJ] AreudArray(sCunne sC, int Aods


int cos)
ine1C] atay = ned int (a0nS]J tcolS]

arrey iUT=SC.nextInt ();

Paiyate Static int CI] feuboAmDferetion (int t1t] QNTeyL

int cols = arrag 1Colength

for(int i=c; ik 005; 4+)


fox ( int =o kcolS; +t )
visioN
G 4 2
Resuut: 2 1
(;-,*): ionopereet Choose
333
222
Arry2 etementS
o Ert1er 1 1
2 1
23 I
I: Asrey foents etem EnteR 2 1
visioN
Scamer: util. ava. imiorct
Soit. seLection uSicg
Weite 5.)
4: (iNT (sest Paint .tua. stem Sy
;i<3;jt)1 j=o int fo(s
i=o:i<3
1t foxint
Reivate
hesett Setukn
kintun("znvalid
in
"tferat Systen.oud
: Case
heeck
; Case
bek
ion) (opeu 4'. SatehCase.
30

Prcblie Class Seletion Sort


Pbeic ctectit Void main StrirgI rps
intl atsOy ned int 1o
mpt koe the
System, out. pseint ln Ente t0 e(ements
IngutArey (ar)
Ipealpam Sete ction soft
Serection Scat (enTY
/ Displauy the Soted arrY
System.bit. (seineanSorted Array i
diselaydragCaroy
SCannet SC = hen Scanner( system.n)
foxine i=o ;i<1O itt)
Systembt, pint Entes e(cment ct Position +
i4:");
Sc.nextnt):

fBciyete Static Void Selection Sot int C] arey


int n= anseycongth
forC int i-o in-t; itt )1
int minLndex =
foc (int /= it1 ;0< n: jtt)
min Index=

visioN
int tenp = otryCmingrder;
anyay[ minnder] = eteyliT:

Psivcete Stectic void displeyAtrey(int LI arry


foxint i=o;i<o : it)
Syst«m.ot. psuint ConrRy (i7+
SystemOut. PRintln:

Q Aoeem het Pompts the 4ser to e t e


a Sfsung nd dispauc he numbek tf Vowels cnd
Consorent5 in the St&ing.
impoxt java.tti.. x
blic Class VOn et Con son ent Counter
Pubtic Stetic Void main Stsirg tIags
Scannex sC= nen ScuneSystem. in'

I ompt use, to eatet StRng


System.out.(kint(Ente a ctaing':
SAing St =sc.next Line C);N
/ tount the no. D Now ets & consonctS
int VoNe CoumtEO
nt Consonamt (out

Il onvet input into konecase


visioN SB= Stto lones, ase();

Entes 10 eemen ts
Ente element ct positb O: 33
ejem cnt t Posi tton 1;22
Entetelement at positt on 2 11
Entee etemet ct Positton 3;55
Entc elemet positton 4 4e
Ete element Ct Positton 5:38
Ente Clement ct
Etee
position 6G6utt
efemenit
EntcA elemet ct
positn8i28at
Entes etement ct positon q : 77
Sord ed Aray :
11 22 38 33 44 55 66 77 88 99
Char ch=Sth. Ch¯t At(i)
{(Cherectet. ISle tter Chj)
Tf( Ch=-a'| ch=-'e | ch =j' |
Ch==o'I ch== y')
VoelComttt
else3
Con sonant Court +t:

7.) Wkte
P&OgsA) thet faompts the 21A to
enteg
`tsuings and displays the luqest
Common rekix th0 StéigS
|mfoxt(aya. itil *
ubtic Class Coumcn frekixfinder i
ubtic Sted ic Void mein (Ztairg J args)
Scuner Sce nen Scanne `ystem. fn:
System out paint ("Ertek the kiast Staing :
Staing St4L = Sc.rext Line):
Syste.04. faino ntex the Serond Sterig :O
visioN
Steing ctA2= sc next line )

ErHee q stirg: faxth VIRTA


Stsing Coamonfu ix =find Comnon fratix (saL, StR2):
Display the sesut:
Syc+em-out.pein &n Lasgest tomnn preix :4 Comon frej)

Psivecte Stetic Stsing frnd (ommon atix(irg Stt


Steirg ste2)
mt minlergth = Meth.min stkllergth(), s42-tonthO);
fox(int t=o : ikmin lergth it)
(s1, chon tt (r)= sA2.charAt)L

hetuun std, Substk.irg (o, minlegtth

Some heb sites imose. Cestetin eles bor pessngd


Wette a metthod thet checks hethek a Stoe ing
Vald pesSWOrd. Suppose the passhod fules
are as A Rassko must heve at least
eght dhnct eks. A password
lettes and diatS A asSnO must (ontein "at
4he sete entey a patshord and disfl<eys
Lnyedd Passhord othesnise
(mfortavg. utilo
visio

OLtpt7)

ErHet the bist stirg: Path Vixja


£rtet the Secord hrirg: Poethik
Losqest Co wmon rebix :'poth
lo

PubaicCIass PassWotdValidato t
Static void maih Sting [ J auqs)
Scanmek Scanhes( System. in ;
Systen.0t. Print Ente a PassWord::
SAving PasSWord= sc.ne xt Line):
/ChecK password is Valid
if( isVatidl Perssaord Cpass word ))L
Sy stem bt Phinttn va lid passAord.
eIse
Sy5ten.ot psint tn Invalid passiord. );

Paiycte Stetie boolecn isVealid Possword(Stig fasskiord)


if (Passhbsd.length()<a)

digit Count = 0;
Check euch chancactes oj the password
fosl chat, ch : Rasskard.toChes Aray ))
if Chanactek is LeHes O; Digtt Ceh))
setuknkalse
if( Chaxact tt. is Digit (ch))L
digitCourt+ +
visiow htuAn digit Count >=2;

Pt.&)
Ente Pesshord : Pesth123
Valid ass Aotd.
11
35

The Curoy and


Stdingring a
Ope Setions
the
in Iaya
basic
acquitees undestan
Concepts SUch as auray types.
ndexing and Sthing methods. The use of oopPZ
Cnd Conditional Statemen ts is Chucia o
electire tray and Stiing menipulation.
fox More Complex tasks, t ilizing
TaYa's huict- in methbds to
Cun tnhance Code aRhays and siing S
teadabitity and re duce
Crmglexiny
Concusion:
In this Eaperiment the oc(Us Was
leconing abat curaqs cmd Stiíngs in (aya
The Pxactiel Ruestions' Coveed key aspe cts,1ncluding
Qorey maniputution Stin opebet ions Cnd the
utiization o attcys nd Sthings nethods The
hands -0n (aciliated Solid toundation
in handing
Prequ.anmitg stings , e5sentiel loh Java

OWht age cqmed odOYs inara and how qee


hey implemented
visio
12

Roggecl atays ce Dhee ech


haye dtheent Dumbes or elemments
They ae
indepernddt arey,ad the Size

int CItJ 47ged Atey = new int C37[J


tagged Avay Lo]= neointJ2 3
Naggd AuayL]- nen it J14,5L
Yaed Aray21- nen) int C]i6,7,8,3
2 Oehentiate String Class Crd Stsirg Bufeh Cks
Oting Class :
Stings in aVa immutcble
Once a Sthing ObËect is cskeotedits
Veue Cun not he changed
S1hing Con Cetenation Cae ateS ne

Ex cmple Steing St = Hello

Stting Bulle Class:

Cun be
- 0pestetims
Charged.
ike append, mset o delete
modity the (ussent Sthing Bukh Object.
Sth.ing Bzu7es is Snchhonized , maKin? it
Exan)ne: Stkirg Bufft Sh= neh Shring 6z{er0:
vision
How (RRte a t)D dimens iond ataay. Instenitte
andl initialize it
I| Deciaution incuntíation and ínitlizetion Df
2D

int It] toDATgy


,2,33{4.5,6i
$T,6,3i

(4) Explain the Stirg anctions hith thei


1. Compase (Ste ing Stat Stsig sta2):
Compare. to Stingsexicoqrathically
"Syrtax int Comfake (Staing Stal, Sthing stA2)

2. ConcatSStting Sai:
" Concdenates the Specitied Steig to end o7 CuTent Sts

3 equals (object onObiet):


" Compares the Content of t0 stAings 7o equality.
" Sntax: bopleqn equals object cnlbiect)

Retuens the (ergth (no. DChasacteS) of the Strizg


iot LengthlO
visioN Symak int CompaseTo( Steirg Stigy 2

You might also like