Page 404 - CA_Blue( J )_Class10
P. 404

C.  Answer the following questions:
                  1.  What will be the output of the following code?
                    char ch[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};
                    for(int i = 0; i < ch.length; i++) {
                          if(ch[i] == 'A' || ch[i] == 'E' || ch[i] == 'I' || ch[i] == 'O' || ch[i] == 'U') {
                               System.out.println(ch[i] + " is vowel");
                    }
                    }
                Ans.  A is vowel
                     E is vowel
                     I is vowel
                  2.  Write the output of the following code:
                    int array[] = new int[5];
                    array[0] = 4;
                    array[1] = 5;
                    array[2] = 5;
                    array[3] = 1;
                    array[4] = 9;
                    System.out.println(array[1] + array[3] - array[4]);
                Ans.  -3
                  3.  What is the difference between linear search and binary search?
                Ans.
                                  Linear Search                                    Binary Search
                     It works on both sorted and unsorted arrays.  It works only on sorted arrays.
                     It starts searching from 0th position.   It starts searching from the middle element and proceeds either to the left
                                                            or to the right depending on the value of the searched element.

                  4.  What is multi-dimensional array?
                Ans.  An array containing two or more subscripts indicating the position of the elements in the array is known as multi-dimensional
                    array.
                  5.  What is sorting?
                Ans.  Sorting is the process of arranging the elements an array in a sequential order either ascending or descending order.

              D.  Assertion and Reasoning based 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): One-dimensional Arrays in Java store elements in a single row or single column.
                     Reason (R): One-dimensional arrays are declared using square brackets after the data type, and the size of the array must be
                    specified at the time of initialization.
                  2.  Assertion (A): Types of Arrays in Java include one-dimensional and two-dimensional arrays.
                     Reason (R): One-dimensional arrays store elements in a multi row or multi column, while two-dimensional arrays represent data
                    in rows and columns by storing arrays of arrays.
                  3.  Assertion (A): The length() method in Java is used to find the length of an array which starts from 0.
                     Reason (R): The length() method returns the number of elements in the array. It is a valid method provided by Java for arrays.
                Ans.  1. a    2. c    3. d
              E.  Case-based questions.                                                        21 st
                                                                                             Century   #Experiential Learning
                    Types of Arrays in Java:                                                   Skills
                     One-dimensional Arrays: One-dimensional arrays are arrays that store elements in a single row or single column.


                402402  Touchpad Computer Applications-X
   399   400   401   402   403   404   405   406   407   408   409