You are on page 1of 2

PRACTICE WORKSHEET 7 CHAPTER : ARRAYS

Q1. WRITE THE OUTPUT OF THE FOLLOWING

1. 2. 3.
public static void main()
{ void printArray () public static void main()
double time[]={12.0, 1.30, 2.15, 2.45, { {
3.15,9.0}; int a[]={0, 5,10, 20,17}; int a[]={5,7,3,11,6,};
int i=1; int i=1;
System.out.println(a); do
while (time[i]) System.out.println(a[7]); {
{ System.out.println(a[i]);
System.out.println(time [++i]); } i++;
} } while(a[i]<=10);
} }

4. 5.
public static void main() public static void main()
{ {
String a[]={“Raj”, ”Rahul”,” Ashish”}; int a[]={2, 7 , 15, 17, 26 ,
20, 44};
for (int i=1; i<=2; i++) int i=1;
System.out.println(i + a[i] + a[i].length()); while (a[i]<20)
} {
System.out.println(a[++i]);
}
}

Q2. ANSWER THE FOLLOWING QUESTIONS

1. Trace errors in the following :

1. 2. 3.

public static void main() public static void main() public static void main()
{ { {
int a[10,5,3,6,7]; // int a[][]=new int[3,3]; int a[]={10,20,30,40}; //
initializing array; int i,j; initializing array;
System.out.println(a.length()); for (i=1; i<=3; i++) display(a[]);
chkArray(a[]); System.out.println(a[i][j]) }
} }
public void display(int a)
public void chkArray() {
{ int i;
// …. Assume code written here for (i=0; i<=a.length; i++)
} System.out.println(a[i]);
}

SHAILESH MANJREKAR – 98194 98104


2. Write the amount in memory bytes that the following arrays occupy

a. int a[]=new int[5];


b. char x[][]=new char[2][2];
c. float f[]=new float[1];

3. Which of the following array declarations are valid / invalid, State reasons – [4]
a. int []marks=new int[];
b. byte age[]=new age[100];
c. boolean status[]=new Boolean[];
d. int a[][]=new int[3,3];

4. Write java statements for the following –

a. Declare an array which can store names of 10 students.

b. Declare an array which can be used to store grades of 10 students inputted by the user.

c. To declare and intialise an array with height of 3 students given as 175.5, 168.8, 171.4.

d. To check if the 5th value of an array named arr is divisible by 2.

5. Consider the following declaration and answer the questions given below
char a[]={‘a’ ,’b’ , ’c’ , ’d’ , ’e’, ’f’ };

a) Write the output of - System.out.println( a[ (a.length/2) – 2 ]);

b) The code following code contains an error , trace and explain


for (int i=0; i<=a.length; i++)
System.out.println(a[i]);

c) Write the output of - System.out.println (a[2] + 2);

d) Write the output of - System.out.println ((char) (a[2]+2)) ;

SHAILESH MANJREKAR – 98194 98104

You might also like