Professional Documents
Culture Documents
Adobe Scan 01 Sep 2023
Adobe Scan 01 Sep 2023
I .
• t jJ; A m1"t'' ' 11 B·ikash11,11Chand11,"Dili "}
11
JJI [ J[ 1 = (
p '
5ttit18 rn II "F
f II11E_s.h a,; . ,
" arJ ~" , "Girish",11Harish"}
1Lishu"} }·
{ lsh an 'Ja sh 1 '"Kamesh",1
11 M . '
,. _
0 ut. pri ntl n( Th e ele me nts of the 3* 4 atn x are:");
sys.. r 111 .
,.1· ll·j<J:1++)
fon 1:::v '
l . )
for(j::::Oj<4 ;J++
. t(m["JU
l system.out.prin 1
J +II II) ;
~ysrem.out .println();
3 *4 Ma tri x are
output : The elements of the
fbe Amit Bikash Chand Dilip
Esha Farjan Girish Harish
Ishan Jashi Kamesh Lishu
•· -...__ _
..... , c~. ,:. ,. .
I:! . ·•r •
C j I
k ~ II ~.
r, 'i r •
int 1.1.
S) ,(,'Ill 11lll 1111111l111 l 1,.• I. :I' '
I I
t,ll(I -O ,t,.\11 t I
in Me th0 .
' r names (string) and click Ok d Ca ll window. Output of th!!
, eote J1l is thus obtained.
f' J, pfOgra
rix are :
The nam es in the mat
Gop al Mohan Kai lash
Bho la Lok esh Jite ndr a
Cancel
utStreamReader Class
/
gram. Th~y
·11g Inpalso, the data are to be entered during execution of the pro
Bf ~SI ethod
-~JS rf)
/o u• of any type. con~ok at
rype: Th e da ta values are entered one by one from the
maY i,e mr . er .. ge by u~ing the
) for egcution . However, It IS ne cessary to give a relevant messa
(a_ of exe
1Jie ume nt to enable the Input editor. /
t stateme wh ich me ans it creates 12 cells in the m~mory
/.llpu •. = new int [3] [4] ;
t m[ ][]
·
syntaX•din4 columns) to store 12 rnteger type numbers. ing
le Dimensional Array by w,
13;;;;lete
0
program to
accept the numbers in Doub
fuputStreamClass is illustrated
as:
. . *·
import 1ava.10. ,
public class Sample
I
public static void main(String
args []) throws IOException
l treamReader(System.in);
mR eader rea d = ne w Inp utS
InputStrea
redReader(read);
BufferedReader in = new Buffe
mt ij;
and Double Dimensional) I
209
Arr ays (Single Dimensional
-- --- - -- ----- __
.,
~~~:=:: :
} ~= .,. .,. --= -~-.,.,.,,,~-,;...._.,,..,....,,.,,.~-
T .. . •
") ·,
. · 1/ll' n- II -~ :ire:
/ . "'/'Ill' r lt-11 1('11 1\ Ill
S.I ~/4'/II 1111 / .J>I 111 /lll(
I
Ii,, (i :.O:j-.J.i ++)
''
.. jtl . . Ill/ ,
.,_ • ,... . IY~ I Jllt'•W • •Jt,,IJ
... ,.,,
.;.: ~\ ·;~..·~·,!~.': ·._,.,_ ,., '11'1 .,,
IH tt•J , J•l1,• •I
:, • • - ,,•r••
.,._ , J' I, ., .. • l- •' I 111 I l l ~ • ll llt' , •,,
ZE IS •
'
args).
-
ht click on the icon Sam ple and select void main(S1ri11g[}
Sttp 2 : Rig
Call Window.
Sttp J : Click Ok in the Method
.
r<-t,hc static void tnain(String arg, []) th
I
lnputStrea1nReader react ===new In S row, IOE.xception
I rinrln( );
s,. :,1(111.l'ur.r
~
}
Systcm.out.println("The names in the matrix arc: ");
for(i=O;i<J;i++)
(
for(j=0~<4;j++)
(
Systcm.out.print(m[i]ij]+" ");
4'..,
~ u......._..,_
- - - . --11'111
r---., JI._.,__.
..... ......uons
.
wtth BlueJ-X
I our.prinrln();
St;tefll-
7
nnrr Class
~fflf: sea, cnls in .a Double
. . .
.
Dimensional Array use the 1"oil owing 'itep.;;:
,· II" flC e en1
•
e..I~11111 I SCJflflL:·r class 1s a member of Java.util package. Hence • linpOrt h
l e packao-
fl' J : • class declaration as shown below: -=e
~1eP ticf()fl,; .
· . ()rl java.uul. *;
unP an objecl of scanner class as:
. create ' .
·ieP Z • r in == new Scanner(System.m);
~ s~anne . . .
· d
a Double D1mens10nal Array of the specific data type ' statinoO requ ire
crea te
srcP 3 : number of rows and columns.
for n:ample,
• for int data type: .
int arr[ ][ J == new mt[2][3];
• for character data type:
char arr[ ][ J == new char[2][3];
• for String data type:
string arr[ ][ J == new String[2][3];
. use two loops such that the outer loop ranges for the number of fO\\:;
4. Now,
Step • whereas, the inner loop _ranges for the ~umber of columns of the arr:iy. u~t!
outer and inner loop vanables representmg row and column subscripts of th~
array respectively. The snippet is as shown below:
• for int data type:
for(i:::O;i<2;i++)
(
for(j:::0;j<3;j++) To store the elements in double
dimensional array row wise, the
arr[iJUJ=in.nextint( ); input stater :mt 1s:
J arr[i] [JI = in.nextlnt( );
To store the elements column
• For character data type:
wise, the input statement can be
for(i::O;i<2;i++) used as:
{ arrU] (1) = in.nextlnt( );
for(j::O;j<3;j++)
arr[i]U]=in.next( ).charAt(O);
}
•For String data type:
for(i==O;i<2;i++)
(
,.·- •-•ti<J;j++)
1
1Ul=in.next( );
1
.
/)iJ1l'J'1.' . l : I I . . f) ou hl ~ D im en '11 111-
'J'Ih_• . • • ,,,.. \\ l ·t·n -~ In ,....fr Hm11: 11' io 1• ·il .\ rr n .r an d
..
il/ \
s b · bl e Dimen,,·onc1J A tr
. dilfrr en c~ 1 Si '" n sion3J A m 1y and D ou
rr1, ,
gI\' cn
> helow · ' e Ween np. t: 1men !
.
1. JI is rcprcscn
rcJ along X-ax;~ anu r..
J. Jt is· ,
h' llf l' ' ln ll 'l
f :ilong X-:ixis. ~-
"'
",_. 1'hc variables with• .,<1me nJ •11 C h-~vt
•
npls reprc~ Cntin . 1•
· ve single typcs ol sub-;c
-"l . ·, hl· ,.•1r ·i;1 hi cs w11 h sa111c name ha
n
mn number 1: ,.
SOLVED PROBLEMS ON S IN G L E D
IM E N S IO N A
ff er en t nu m be rs
L ARRAYS
in a Sin gl e Dime
(SDA)
.
.
to accept 20 di m be rs w hi ch ar
ior,~
e di v,· ~bslq
Prog. 1 Write a pr og ra m o f al l th e nu SJ .
isplay the sum !
Array (SDA). D
,
ei th er 3 or 5.
3 or 5
m be rs w hi ch are di vi si bl e by
sum o f nu
// To display rhe
import java.util
. *;
public class Sum
/ [])
main(String args
public static void
(
Scanner(Syst em.in);
Scanner in=new
int i,s=O;
0];
int mf]=new int[2
for(i=0;i<20;i++)
{
the cell :");
1.out.p ri nt("E nt er the number in
Sy~1e~
mf1J=rn.nextlnt();
}
for(i=0;i<20;i++)
(
m[i]%5==0)
if(m[i]%3==0 II
s=s+m[i];
s);
.out.printJn("The s nu m be rs di vi si ble by 3 or 5:"+
System um o f
J
ing c eJ -X
~ 214 I Understand omputer Applica
tions With B lu
'~
- th e .,~
&nta r
Snt•rth• n r i n t he
Enter th e UIQb•.r J.. n the c•.1. 1 : 33
n Wllbez; ce.1. 1
ltnte r the n'-'-~ - in the c ' : 44
&nter t he
- -...r
llUJnb
i
n
•...,1
t h• <::e1
l
: 2
er i n t 1 : 55
Enter the n'lDlb h e ce
11 : 31
•r ~n
Enter t h e n ~ the c •l l
r in th : g1
Enter the llUIQb • ce11
er in th : 93
Enter th e n'lDlb e ce11 .
er i n th .77
Enter the nUIQb e ce1 1 .
er in th . 53
The • wn o r n\llllbe r . e ce11 : 78
• di"i•ibl
e by 3
Or 5 : 1 79
=" t 111:rx):
1crn.out.p ri111l11(" Tlll' grc:11c:-.1 nf rite arr:1y ck111cn,..,
Sy~ J:
nf llil ' :11ray ck111c11h =.:" +111in
-.1cm.,)lll.pri111l11(''Tlll' s111:ilh..·:-.t
Sy:
}
IJ.in ):
Scanner in = new Sc.:anncr(S) ,ll'I
int i.j.c.: I =0 .c2 =0 :
inr ph) I l = new inrf-rnl :
int d1l'mf I = new in1j-WJ:
int ma th., ! j = nl'w intl-10] ;
for ( i=O:i< -+0:i ++ )
3 () >= ~())
if((phyfiJ+dlL'lllliJ+111 ;11h,j ij)/
cl+ + :
() <= 3 ➔ )
if((ph)lil+d1l·rnliJ+m.11h,/iP/3
c.::!++ :
of ,1uJc11i,; ~d li, 1,, M) ', arid Jh1 >\l. '', r' '+.._· 11.
Sy))fl'lll .ou1 .pri111ln( ''~u111ll\."r
of ,111J~ 11 1-. gl' llin : J4' ; .in,J hch w. \r" ♦ t· 2 i;
S) ~1crn.ou1.pri111ln( ''N um ha ,
I
<.
~
l'J •-·X
216 1 Und<'r,1.ind111J: Com
J'ul n AJlp lu atton.!I "Ith Ulu
l
WrilC a p ro g ra111 111 a vn· ,,1 I !J .
. );\ ) . N. o w, l' lll e r ,. , 11111
j\rraY (SI d11f t· 11· I
1il wr II. 11111111 11 · 1 ... 111"
. ~, ,, ., I,· I) 11
•11uc
c~cnl or nol rn lhl" l i~I
''1 ,.,,:,y (·I~·11 w 1,1..,
. .i 11d '-l':, 11 Ii ' 11rw1, .1r :,il
1,y w. lll'll wr Iii•·- 1,r111,l 11. r 1
rr
(CC "1 • ' 1t II'. I ,11- w ·,r '
11 -.. 111•• '
, h,plc
11
npul: ·· ••·,n cl ,
111 I
5
nl I l 111 21 nl J J 11 l"i l
nlOI 1117 1
56 62 77 <,7
74 ~rJ
sample Ourpul:
Enter a number lo be searched : 4 2
The number is present
s .
I ntln("The number is not present");
c, \ in ·1 s·
.:Cl't'pl 20
:
inll'r!LT fll //l lh •. ing/i.; /)·111,cn,
Wrirc ,J pr, 1/ f.l lll 111
Prog. 7 1/J,• /11/hn,111i,! :
,d d,,pl.i) ' •r,~
.-\ 1r.1) I ·111d .11
I ~.
11I t'f f/ l lll lll il ll'
I. .\ 1111 1/i('f
1111111l11·1\
11. ,\ u, ul ,l· r 1,/ 11dd
JJI. ,\1111ilw1 ,,1 11111/1,pln 11/ -1.
11111/tip ln 111 •I
. odd .111d
1111111k1 11/ nl 'II
:. l11 d, , pl.11
1 1 il 1.11.1111d
'
lll lf'
l l.1,, ,\ i1 1i lk f
lll .i11 );
:: Ill'\\ Sr;11111t·1(Sy:-.ll'
Sl ,ll lll lT i11
O;
i111 i._j.l'/.:O.l·~=-11.c.L
1/ IO/:
inf .,/ I = 1JC11 111
2(1 lll lll llk 'f. ~ ") ;
s~ ,1c111.n111.1•11111 /11( T n ll' f
/111 ( i::: 0. i<:O.i
++ )
11():
.1/1/ :::: i11 .11n1/1
hl l( i=0.i<20.i++)
1r'(.1/Wr2 == OJ
d + +:
i((a[i]'r2 != 0)
c2++:
if(:i/i]<:"c4 == 0)
d++:
1);
1ln("N um ber of even numbers\t"+c
S) ~rem .o u1.p rin
bers\t "+c2);
em .o ur .prin rln ("N umber of odd num
Sy~r 4\t"+c3);
.o ur.p rin1l n ("N umber of multiples of
Sys1em
}
mensional
a set of IO integers in a Single Di
program to accept nding order by us
ing the 'Bubble
Prog. 8 Write a bers in as ce
Array (SDA). Sort
the nu m
array. [ICSE 2005 , 2013/
isplay the so rted
Sort' technique. D
technique
th e nu m bers by using Bubble Sort
II To arrange
import java.util. *;
ding
public class Ascen
t
main(String args[])
public static void
t
J- X
. tions with Bl ue
• -fll'W .\l';rllllt· r( Sv,1v 111 , ;, I >·,
,•( 111- •
/j~·)l1~ .
·/11 iJ-'• •\\' inf( I Uf ;
I W"'''
I JII · ., f{l,i++)
I/I ,..jl;I._
I•
·,rt,,..
I , ,111 .p1i1ll ( '' / · 11k1 1111111'11· 1, i11 1111.: l"l'/1 :") ,·
. ,,,.,11,1
:,,11 ·1; 111 flL'\ f/111 ( ),
fll I
I . o i ,1 l
f,'n
•' ,...
f,;.. •
,.,,,t . I,,..
. ('1-i):jH )
.- (
'
I_ tl:;,1111.itl/)
,u,111
I
1:::J11UI:
flllil:::1111.i+ I 1:
·+IJ:::I:
,11 L'
new Scanner(System.in);
.area;
J
int i: =O.i;
l l: ,l .... 11
thl ll 11 • , II :· lll' W 1h111hkl •III\.
Sy~ll'lll.1111\.{)I .-Ill 1l 1l " h1 h' I thl ' '. llk 'I 111 1111 ,,
I · · 111:11q•k 1:
'I ::; ill .lll'\11 ), 111hk( 1;
s~ = in .n~,1D,111hkl );
sJ = in .1w\tD,111hk( L
Sr tl. 'll \.lllll.pii111h1l"
F111,·1 ''" ' all ',\Vl' I'.,
11I ,\(I ,,1111k1il ·,'' ,.
fN(i =lU <~l);i t +)
ans\ i\=in .n~xl l), iuhkl );
il\(sl-ts~) >s3 & & (s2•
s3) >s l ,"'18:. h i l \ .\) ,•,'n
System.out.print\n("Tria
nglc fon11alion is 1101 pm
) ,!>i hl,·'' J;
s::: s + J:
I
break;
,ase 2:
for(i::O;i<lO;i++)
I
if(a[i]o/o 7 == 0 II a[i1% l O == 7)
System.out.pri ntln( a[i 1);
break;
default:
System.out.println(" Invalid choice");
l
l
I
for(i:::O;i<39:i++)
I
for(j:::0:j<(39-i):j++)
I
if(marksUl<marksu+ I))
{
l=rollU);
rollU]=rollLi+ I];
roll U+ I]=t;
l=marksU);
marksUJ=marksLi+ I].
marksLi+ I]=t· '
} '
}
I
Systcm.outprintln("
S...;,<41)',i+t) Roll No·\t"+"Marks");
fol(r-"··
I
,__out.println(roll(i]+
. "\t" +marks[i]);
Wilb Blue.J-x
., pf10GRAMS ON DOUBLE DIMENSIONAL. ARRAYS
~"'"p I"',~r.,m in_J•''." '" ,t:•r, th,· 'I""''"''' in " l '4 nia_tri, in a O,iuhlc
£
t
.J
r
j
\\rilL ,. ,
•11'1' 11
ni1'''
' . ,.,y I
h.
J1'r I. 1111'111 :
,;.,1111' L 1,1·1~ ,,r
• , 1111111
l
, 1 ,\n.1) . I 111 J ,h~ :-um ol a\\ thi.: m11\llwr~ ol the matnx and
1
'
.
, 11111 11~111 b
.
,Ill rnput ~l.lll' ll\l'nl
., , I I.\ 1-1
111~
I, ~I ~I -' ·'
1J '\{) ~I)
I II ·
(l ,. ()utl'\11 :
S·11111'\:lll ,1f thl.' l.'kllll.'l\tS in 1h1' matrix is 340
1111.' ~
ill ,,f 1h1· matrix ckml.'nts
111.' ~11
1,
,1,1~ ♦ •
\',. Ji"' 1,,.1- 111\ • •
-~J· . J,l~ll 111
·.' ' ~1,1•'
, .-:, . n1;1i11(St1in~ ar~s \ I)
.. ,.,,,,1
. ,pll•
'·
. •\\' S1·a11111·r(Systl.'m.in);
! ·r io::::lll •
. ;1\11'
:-- . .,:::{l:
J::::oi:w int\ 31 I41;
.,:: 1•.1-~·
ll nrintln(Entl.'r the numbers of the matrix")·
:ii 111 \
'. ~~-'. '
~) -c::1fr:J:1++)
1.in'~ ,
I -~)j-'4j++)
f,irtJ- tl t()·
i11[i]LiJ::::in.nex n ,
I . )
f0rtj:::Oj< 4:J++
I
system.out.print(m[i)Li1+" ");
I
System.out.println();
I
for(i::O;i<l;i++)
I
for(j=Oj<4;j++)
{
s=s+mli]Lil;
''
System.out.println("The sum of the elements in the matrix is "+s);
I
I
Wrire a ~gra'.11 in J.tva to More lhc
Double D1men1o1onill Arrny. Find lh , t . lltt111hl',- .
C 11 "h ' \ 111
die matn~ by usmg an input Ma1cnicnt C\I iln<J lh ~ 1t
• • •
<-,
u...-,._ ........ """lllaoHc
I . itn(lhc hml'.'-1 nu1nhi.:r 1111 ~ . . _
,rttl . l~ ,I IT.t \ I\ " ,
l ,.,,,11 I . tln('Thc h1ght:,t nu1nhl•r in ll , . . +r,1111 '·
,,11 pflll ll: ,Ht,1 \ h '
•'. ,I .,,,.,,111 - · ~ 111.1\ I,
.r•
•'
I
Scanner in=new Scanner(System.in);
int ij;
intm[ ]( ]=new int[4][4] ;
int n[ )[ ]=new int[ 4][ 4];
System.out.println("Enter the numbers of thl! matrix");
flll{i=O;i<4;i++)
I
fll(j::()j<4j++)
m[ilU)=in.nextlnt();
I
S~println("The numbers of the matrix arc:");
I
' 1llI • ~
~, ,,~·m , ,,11 t'' 11~h n~ 11, '' )•
s~ ',:~·m \l~;t pn ::t: n(' 111'-· Ir.in,("-"--' ,,f Ih. .• 111.11 ri \ i~: "):
(,,:,I =1 l.1,-t1+--+)
I
'
f,lf\l =\ I._1...:. J .J +--♦)
I
s~ ,t,·m ,•ut rnnttnl illll~ .. "l:
uapul ~ D I . .
Seq,k Input
1'e •mbers of~ matrix are:
ll 21 IJ 14
)I ,1 , • .u
61 II JD 29
JIG4176
SF ,,, a.a-.
4-lit-fll• •-• of each row:
. :1t.tf ti r■Ells of Ist row = 60
·;lu rlfl of 2nd row= 149
ol Jnt row= 131
row= 258
I '·
I 11,,intln("ThL'
,•111.llll .
1H11nh1.·1.., ,,t thl· 111 ,,, 11 , ,
,,
\ \ 11111. • )
·· '.{l,i•:J:i++
1,•:11
I . -~)jd :j++ I
1,111J~ .
s,·,I11.•111.,mt.pnnt
· I11( "·r·1ll' :-.11111 ut the L'lr111l J1h ,,t , . • :1 !
1,;rtidl:i<.i:i++ )
I
r-0:
for(j:{):j<•tj++)
I
r=r+mli)Lil :
I
System.out.println("Thl' ~u111 ot 1li1.· ~·k111,·nt-. l 't •11~lt• 111., •11
I
System.out.println("Tlu: ~um of till.' l'k1111.·11h 11t L',1,h L·1•\11m:~ · 1:
fixti~~k4~i++)
I
C::0;
f(lfja();j<4j++)
1.':::l' tlllljll1 l: • ., 1 ,I " I Ii t I) t " n, l1 111111
Il J.
• ,. 11 11 I 11
1
' l 11 f I111. I
s~ :-ll'lll.llllt.pri111l11(''lhl' :-,11111
I
1
_ th~ 111111il)l'f':-. in •I ·1 tll:ilti .
,,11L' I X 111 ,
. J ·1\;1 ,,, " "f rite 1111111 ,en, of Ilic I ,11>1,
(II ,11 • I ...11111 . l'f I I 111'11 1
1
Pro)!. 16 \\'rit~ a.pn'.~!r;•
, , .-.,y. ,:;nil . ·.; ,,1 I1it.:
1 1L : . dghl d1a go11;d of Ilic n, ·
, 1 rt. x Ii
t 1;11,' 11.,
/
Scanner in=new Scanner(Sys1em.in);
int i.j.ld.rd.k;ld=0:rd=O;
int m/ J( J=new inrf4Jf4J;
Sysrem.ou1.prin1ln("Enter the numbers of the matrix:");
for(i=0:i<4:i++)
I
for(j=O:j<4:j++)
mf iJUJ=in.nexllnt();
J
System.out.println("The number .
for(i=0;i<4;i++) s of the matrix are:");
(
for(j=OJ<4J++)
l
}System.out.pnnt(m[lJ[jJ+"
. . ");
System.out.println()·
23 '
o/ Understanding Comp
uter Appli .
cations With BlueJ-X
I . () ,.. I .I I I )
(I · .
11 11
.f,Hnil d/il :
~-'. .
t~l
I •111
,111 I'' 111tl11 ('' I lie
t
, 11111 111
"' '" ).
I ~ 1,
" - · - ti.I"•' l . I ♦ I I
,·,,n •
I 111' i II f.. I,
I ,I I I 11
~ · ~ f;
I ,
1111
1111(""lfa· , 11 111 11 1' Ilic right di.1~1111.il d r mrnh =-"+rd) ·
. t •Ill I I I 111
. •
~~ .. 4
\\'nil' a pn 1,1!1-:t111 i11 J,l\·:r ll1 :--lorl' 1l1L' m 1111bcrs in l\.\.o diJfl:n:nl D1111hle
J)itn'-·n,i(lnal Arr,iys 111H I 1-1 I and 111-11 /4 J. Fi11J Ilic sum of the 1111111hcr:--
nf th'-' "·01n·:--p1111Ji11~ ckll lL'IIIS pf' lhl' 1wo arrays 111 and n anJ :--1,,rc them
in th~ amt)' pf -1 J HI by usi ng .111 lnpul stalc111cn1. Oi:--pl;,iy the d..:rncnts
of amt)' p in a 111a1ri~ form.
s:unrk Input : Sample Output :
Array n Array p
Array 111
8 22 3I 15 20 45 64 37
23 JJ 22
12
11 16 30 26 31 47 74 36
JI 4➔ 10
20
17 25 33 20 42 39 41
:s 14 8 JO
JO
24 21 32 53 76 45 44
24 12 12
~I 52
S>stern.out ·
fnr1· • pnntJn( "Enter the numbers of the first matrix");
-\i::o-J<4;.i++)
I
~•a++>
Arrays (Single Dimensional and Do uble Dimc nw,n,1/) f 2:1 I
F
>
n,! i 11 jl=-111tcgcr.p.1r:-dnt(in .rc.1dlinc() ):
I
.. . ,
.. l.nll'r . 1· I , • · rnd matri, "):
S),tL·111.11t1t p1111tl11( the 1111111hl'I!'> n t 11.: :-ul
f111( 1=0 .i<-1:i H)
for(j=O:j<~ :j ++)
I
rl i JU ]=ml i lli J+nliJLil:
System.out.pri nt(pl i]Li]+" "):
}
System.out. println();
}
ProJ?. 18 Write a program to store a day, its maximum tempaature, its minimum
temperature in a Double Dimensional Array of 7*3. The program acc,'pb
a particular day of the week and displays the maximum and minimum
temperature of that day. Use an Input statement for the same.
.
- .rea
<
J