Page 119 - CTS - CSA TP - Volume 2
P. 119

COMPUTER SOFTWARE APPLICATION - CITS





           Output:



















           Explanation:
           •  In this program, we define a method isSorted that takes an array of integers as a parameter and checks if the
              elements of the array are sorted in ascending order.
           •  We declare an array numbers containing integers in the main method.
           •  We call the isSorted method and pass the numbers array as an argument.

           •  Inside the isSorted method, we iterate through the array and compare adjacent elements to check if they are
              in ascending order.
           •  If any element is greater than the next element, we return false, indicating that the array is not sorted.
           •  If all elements are in ascending order, we return true, indicating that the array is sorted.

           These examples demonstrate various operations that can be performed on arrays by passing them to methods in
           Java. Passing arrays to methods allows us to encapsulate array-related logic and promote code reusability and
           readability.











































                                                           104

                               CITS : IT & ITES - Computer Software Application - Exercise 95
   114   115   116   117   118   119   120   121   122   123   124