0% found this document useful (0 votes)
10 views8 pages

B22ai019 Oopj T12 Solutions

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)
10 views8 pages

B22ai019 Oopj T12 Solutions

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/ 8

BAIO 19 T-1:

)Develop a java pogram to read a Rle


oords and
and COunt he Durmber of I?oe S,
charatters pvescot î the le.
A: import iava.lo. Ruffeve d Reade,
fmport java-fo. Ffle Reader,
ionpovt java. fo.10E xee Phonj
class fle (ounteY

public statie vod mato (stingLJorgs)


"Rle. t"
RleName
iy Shing
t t Pot ineount =0)
Pnt cwod(ount:oj
?nt char (ount0j
(Buftekeadex Yeader new BuferedReader
ry
(new Me Reader (fle nvame)))
Stiha oe
Sing,
twhin( (ine rader.readline0)! nulD

ioe Counttt)
chavtount + 4ioelerg th);
coord s afoe.split(" ");
StingtJ
cwodCount t oovds leng thj
ftath (10¬xception e)
System e piotAn("Eviov reading the
le: "+ C- gEimessage),
ln("unes: "4 fire ount;
Sustemout- pint "Acoord(ount)
out. pintn (wovdes:
Syt tem (characters: "HcharCount );
System out tn
pin

to combioe tuoo fles int


) Develop aajava
ava pgram

4: inpost Javo-u tl
class Tes
throos
publfe static voîd maf (stvingarqs)
TOEXtephon

fle+nputstream Finecw fileInputStreamtrt be


fle30put Stream fa:neo FleInat Jtveam"Xtb
Ffle autput Stream fout:neu fleoutaut s tream
("Foutputtx+);
SequenteInput Streqm tomb new Sequen ceInpt
Stream(fif) >
uohite(; tormbread o<:-)
fout "oite (i;
(omb-close);
tcloset
fa-tlose();
foutlose)
) 0evelop a jav oqnam us ing Comm and ine
arguments a lollou's
IF (omnmand line arument ave ?ero,tho
code has to vead fiom teyboavd ond cort
onto Console
the code
If (ommand ine avqtumeot are one nam 7s
bas to dead from he 5le cohose
Jhe
menhoned as art oF he command
arqument and covite the (onteots of that
Fle ooto Scree.
Ie (ommand ine arqumeot ve tOO the ode
has to vead fom he Nle ohose name ?s
mentioned a part OF the Srst Commad
ine avqumeot ond.ortte the tonteots ito
anoth er fle uobose name s meotoned as
part oF Second command line arqument
A Rmpot javaubl*;
Qublic ctass OataReaderl nter

publie stoie Void maio (String(3args)

try.
BufferedReader reader
Buffered Wnter wrternul

iF (args lerg th o)
reader:newSu ffaedReader (0euo Inedstieam
Reader (systtmin)
oniter:nw Buf fevedwriter (neu Outrutstrearn
Reaaer (Systemiout)
Bollacdkeoder(new ilel coderloi
Noda:neo ButhodBothiter
tonteo:ncw
QuteitSteam
long Iinghd: 2)
che
Bffevcd Reader(new AleReodev (agi
Fodcv :nw
Bufioed ite vnew ile
ilebitt(arq
n("Tnalid num ber oF aroue
argumeot
stem cut pint

Stuing bne:
vaderxeodLine)- Qul)
chile( ine
viteroeotite tine)
coiter-nelinel)

YeadeI-tlose);
Ornter tlose);
cotch(10fcPtoo e)

Systmout print n tupn eror ouvr ed:


) vckp a jova poqvam o reote too thorads.
lhe lioo hv(ods have o pint he
(0 he hrd oimes a0d for everq Sco
So Setoc

vrod| and evey

H class my Thread exkods thvead.


pivatt int puot Jnteval;
Ablfe Thcad (sting name ,fnt pint Intna)
Superéname)j
val;
Ahiso punt Interval: printznt
public vod un

for(ot P: oj iclojiHt)
pnntlo (Tbread. Curent Thrcad)qtt
Systen0ut

ty
oslecp (eint Tatoval);
Thiead
cotch(TntEYrupled Ex«ephon e)
S
eopnt StockTvave 0;
T°oThrcadfxam
(loc
ain (Shngtavgs)
blr tloh, vod
y lhread(" he
Myhwrad hrrad |:neo thread ("
My
MyThv¢ad thrrad 2:
Hhcad| Start);
neo
("hread
thveadQ.start

threa d 2.join;
ted Excephon e)
JCatch/Tntera p
e.printstart rane(

(°8oth threoi ds have


Sqstem out-printin
Bashed

threads to fnd-he atpt


Apply the tontept oF
OF
3
GF the beloa Code block.
class yhveod inplements Runna ble

Syutm out pntin ("Ron,

(lass iest

puble static void main (Sting (3arg

mythread t neo Mlhread ();


t t t ; tstart)
System-oul'print An (" main"),

Gutut Run

Output

ERROR
6) (la Tett oolemnts
înplrme Ronnable
publfc Vovd un)

Sykm outproitn("Ron),

lats ayctass
publk staie void main ting
iavgi)
Thread tIkneo Thread();
ti-ftatte start)
Systm oui puntn(mako");

Output
maßo

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