0% found this document useful (0 votes)
25 views

Arrays

The document discusses errors in code snippets and ways to identify and correct them. It also contains multiple code examples demonstrating array handling and operations like filling arrays, sorting, reversing, etc.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Arrays

The document discusses errors in code snippets and ways to identify and correct them. It also contains multiple code examples demonstrating array handling and operations like filling arrays, sorting, reversing, etc.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

below contaln errors.

e )W h a t
is
the
codes
given ldentify the errors
of
Question2:. :
Some
Write the output
2, 29, 91;
them.

45, 4, 92,
andcorrect

=
=
5,
(25,
5, 4
25,+ad[7]1) /ad[5];
all
a d l ]
+ a

ap)
"
( a d / o
==
"+
+
Result
Result

int =

Sistenn.out.prin
i n ta p
int("
20, 30);
=
{10,
CQ[i]++; CQ[3]++;
CQll
nt
i n tC

CO]++;

3:j++)
<
= 0;j "+COljl);
, +CQlil):
or(intj
Svstem.out.print ("
77, 33, 55);
55};
{11, 44,
LP[] = <=4;j++)
int 0;j
or(intj
=

P[4] + LP14):
= +LP[4) "
LPil+=j =

System.outprint("
LP
5.57, 6.23, 7.25:
{3.12, 4.64,
double KB[]=
) j++)
intj 0;j <=5; =

for(
KBli] = (int)KBIjl;
=
"
+ KB[2]);
System.out.print("KB[2]

6.23, 7.25];
double FZ]
= {3.12, 4.64, 5.57,
e)
boolean asC =true;
<= 3; j++)
for( intj 0; j =

iH(FZIj]> FZj+1]))

asc false;

y'stem.out.print(" ASC =
"
+ asc);
int GY[= {3.12, 4.64, 5.57, 6.23, 7.25);
boolean desc true; =

for int j 0; i<=3; j++) =

GYj]>GY[j+1]) 335
desc false;
break;

"
+ desc);
System.out.print(" DESC
=

652, 782 ;
g) int YM[]= {512, 312, 452,
boolean all = true;

tor(int j 0;j < = 5; j++)

if(YM[j1%10 = 2)

all false;

"+ all);
Svstem.out.print("ALL
=

(h) (i) int MW[] {21, 56, 31, 459, 52,


= 742, 26];
boolean some = false;

for(intj 0;j MW.length; j++)


= <

if (MW[j]/100 > 0)

System.out.print("Some Value is: "+ MW[i);


some true;
break

System.out.print(" SOME = " + some);

(i) In the above code hi), replace the array by int MW[ ] {56, 21, 33, 78, 95
=

() int ZR[] =
{0,0, 0, 0, 0,0, 0};
ZR[O] = 2;
for(int j 1;j < ZR.length; j++)
=

ZRIj] =ZRj -1] *2;

System.out.print(" The array is: ");


for(intj 0:j< ZR.length; j++)
=

System.out.print (" "+ ZR[l);


j) int HC[ l= {1,2,3, 4, 5, 6};
intn
HC.length 1;
= -

for(intj 0;j <= n/2; j++)


=
The array is: ")
lprntln

Clength; ji s)
0i
m.nil.print(" " + H C
4HClil);
11/ 1 ,22,,3
22 33, 44, 55, 66, 77
I1.length 1;
l i - 0 1 n / 2 ;j+4)
f

WHil
1ntH/-W7l/n
m -il:
iln- tmp;

Ssem.out.print( The array is: ");

0;j< WH.length; j++)


int j
=

stem.out.print(" +WHil);

12=
new
int[5];

0;j<=nj++)

7int j =
sistem.out.print(" "+DL[j]);
:oid main)

Sring SN[]
=
("D", "E", "F", "R", "O", "S", "T", "E", "D";
int n = SN.length;
1;j=j +1)
intj =0;j<=SN.length
-

for

System.out.print(" "+ SN [G]);


iff%2 == 0)

System.out.printn();

"LIA ;
"RIA", "ICE", "LAND", "MONG0,
gCNIJ=|"SIBE",
int n= CN.length;
torlintj 0; ji<=n-2;j++)
=

ystem.out.print(" " + CN [jl);

ifj %2 1=0)
337
Continue;

System.out.println("+ " + C N [j+1]);

(o) String WKDI] = {"SUN", "MON", "TUE", "WED", "THU" "E


int n = WKD.length;
"FRI, "SAT",}
for(intj = 0;j <=n-1; j++)

System.out.print(" "+WKDlil);
ifWKDil.charAt(0) == "T)

System.out.println(" ");

(p) void main()

String SNI] = ("A", "B", "C", "D", "E", "F", "G", "H";
int n =
SN.length;
for(intj =n-1;j >=0;j =j-1)
System.out.println(" * " +SN[il);

ifj % 2 != 0)

continue;

System.out.println(" #" + SN[jl):


ARRAY HANDLING
s TAI | and TB| | of size 7 and
type
that contains the elements of theinteger
each.
second arrayCreate
F i l ltwo arr
a
third rrav TC (TBI )
h y the elements of the first array (TA| ).

r e m p l e :

TAI 21 31 41 51 61 23
Input:
43
TBI1 28 38 48 58 68 78 16
utput: TT[ ]| 28 38 48 58 68 78 16
21 31 41 51 61 23 43
Create dString
Stri array SR[ J of size 7, Store the weekdays in it. Input an
integer, weekDa DayNum and print the corresponding weekDayName. Note
that
nst day of a Week is "SUNDAY". Check validity range of input.
Forexample:
Input weekDayNum: 2
Output: weekDayName: MONDAY
Input: weekDayNum 9

Outout: weekDayName: Sorry! No such day.


7. color names in it. Print the first
ielCreate a String array CRI] of size Input
color name.
letter of each
Forexample:
Green Yellow Magenta Blue Orange Violet Indigo
Input: CR[ ]
Output G Y M B V
size 5. nput names of Indian Monuments.
f Create a String array DCI Jof
with 'H.
Print those names which start

For example LalQuila HampiTemple


Input: DC[1QutubMinar TajMahal HawaMahal
Output: HawaMahal HampiTemple
variables. Create
of int and size 10 and fill it with
g)Create an array ZR[] type elements of array
another NZR| that contains only the non zero
array
ZR{.
For example: 0 45 0 0
25 0
Input: ZR[ ] 100 405 84 0
84 25 45
Output: NZR[ ]100 405
with variables. Create
of type int and size 8 and fill it
a e array RW| of RWI | in front
àn
the even elements
contains
e r array EW[ ] that
ollowed by the odd elements.
For example: 54 29 83 44
87
Input RW[ 31 45 62
45 87 29 83
44 31
Output: EW[] 54 62 int and size 8 and
fill them
) Crea and STQL, both of
type all the elements
wiW arrays STPU array STUN]
that contains
frdrlables. Create a third 339
DOth he arrays without any repetition.

You might also like