Page 391 - ComputerScience_Class_11
P. 391
2. What are the main drawbacks of the arrays in Java?
Ans. The main drawbacks of arrays in Java are:
• Fixed Size: Once an array is created, its size is fixed and cannot be changed.
• Inefficient Memory Usage: If you don’t know the exact number of elements needed in advance, an array might either be
too small.
• Homogeneous Data: Arrays in Java can only store elements of the same type.
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. Assertion (A): An array allows the storage of values of different data types.
Reason (R): An array is a collection of data of a similar type.
Ans. d. A is false but R is true.
2. Assertion (A): In Java, the index of an array starts from 0.
Reason (R): The first element of an array is always accessed using index 1 in most programming languages.
Ans. c. A is true but R is false.
3. Assertion (A): Linear search works efficiently on unsorted data.
Reason (R): Linear search checks each element sequentially until the desired element is found.
Ans. a. Both A and R are true and R is the correct explanation of A.
F. Case study-based questions.
Aakash is developing a Java program for managing the grades of students in his school. He is using arrays to store the student
names and their grades in different subjects. The program calculates the average score of each student based on their marks.
Aakash uses two separate arrays: one to store student names and another to store their marks. He then uses a single-dimensional
array to store the marks of each student. The user is prompted to input the student names and their marks and then the program
calculates the average marks for each student using calculateAverage() method.
Later, Aakash decides to implement an insertion operation where he adds new marks for a student at any specified position in
the array. However, he faces an issue when he tries to insert a student's new marks into the existing array, as the array does not
automatically adjust its size.
Based on the given case, answer the following questions:
1. What type of array is Aakash using to store the marks of the students?
a. Single-dimensional array b. Double-dimensional array
c. Multi-dimensional array d. ArrayList
2. Why does Aakash face an issue when he tries to insert new marks for a student in the array?
a. Because arrays cannot store duplicate values b. Because arrays are of fixed size
c. Because the array was not properly initialized d. Because the array is not initialized with default values
3. What would be the correct way to increase the size of an array to accommodate additional student marks?
a. Use the add() method of the ArrayList class b. Use the resize() method of the array
c. Declare a new array with a larger size d. Add new marks directly to the existing array
4. What method would Aakash need to use to calculate the average marks for each student?
a. sum() b. calculateAverage()
c. length() d. average()
Answers
1. a 2. b 3. c 4. b
Arrays 389

