***** JAVA *****Write the inOrder() method, which has an arrayof integers as a parameter, and returns true if the numbers aresorted (in order from low to high) or false otherwise. The programoutputs "In order" if the array is sorted, or "Not in order" if thearray is not sorted.
Ex: If the array passed to the inOrder() method is [5, 6, 7, 8,3], then the method returns false and the program outputs:
Ex: If the array passed to the inOrder() method is [5, 6, 7, 8 ,10], then the method returns true and the program outputs:
public class Sorting { public boolean inOrder(int [] nums) { /* Type your code here. */ } public static void main(String[] args) { Sorting s = new Sorting(); // Test out-of-order example. int [] nums1 = {5, 6, 7, 8, 3}; if(s.inOrder(nums1)){ System.out.println("Inorder"); }else{ System.out.println("Not inorder"); } // Test in-order example. int [] nums2 = {5, 6, 7, 8, 10}; if(s.inOrder(nums2)){ System.out.println("Inorder"); }else{ System.out.println("Not inorder"); } }}
***** JAVA *****Write the inOrder() method, which has an array of integers as a parameter, and returns true if the numbe
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am