***** JAVA *****Write the inOrder() method, which has an array of integers as a parameter, and returns true if the numbe

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

***** JAVA *****Write the inOrder() method, which has an array of integers as a parameter, and returns true if the numbe

Post by answerhappygod »

***** 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"); } }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply