Page 360 - ComputerScience_Class_11
P. 360

16               {

                17                    secondaryDiagonalSum+= arr[i][3 - i];

                18               }

                19               System.out.println("\nSum of Secondary Diagonal: " + secondaryDiagonalSum);
                20               int totalSum = mainDiagonalSum + secondaryDiagonalSum;

                21               System.out.println("\nSum of diagonal elements: " + totalSum);

                22           }

                23       }


              To take value from the user,


















              The output of the preceding program is as follows:
                      BlueJ: Terminal Window - Java

                   Options
                  Main Diagonal:
                  Sum of Main Diagonal: 30

                  Secondary Diagonal:
                  Sum of Secondary Diagonal: 30
                  Sum of diagonal elements: 60





                   11.9 SORTING VS. SEARCHING
              The differences between sorting and searching are given below:

                                        Sorting                                       Searching

                    1.  Arranging  the array elements in  ascending  or  1.  Finding an element in the array.
                      descending order.

                    2.  Two types of  sorting  are:  bubble  sort and  selection  2.  Two types of searching are: linear search and binary
                      sort.                                           search.






                  358  Touchpad Computer Science (Ver. 3.0)-XI
   355   356   357   358   359   360   361   362   363   364   365