1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kobusy [5.1K]
3 years ago
5

Write a static method named isSorted that takes an array of real numbers as a parameter and that returns true if the list is in

sorted (nondecreasing) order and false otherwise. For example, if variables named list1 and list2 refer to arrays containing {16.1, 12.3, 22.2, 14.4} and {1.5, 4.3, 7.0, 19.5, 25.1, 46.2} respectively, the calls of isSorted(list1) and isSorted(list2) should return false and true respectively. Assume the array has at least one element. A one-element array is considered to be sorted.
Test your code with the following class:
public class TestIsSorted {
public static void main(String[] args) {
double[] a1 = {16.1, 25.3, 12.2, 44.4};
double[] a2 = {1.5, 4.3, 7.0, 19.5, 25.1, 46.2};
double[] a3 = {42.0};
System.out.println(isSorted(a1)); // false
System.out.println(isSorted(a2)); // true
System.out.println(isSorted(a3)); // true
}
// your code goes here
}
Computers and Technology
1 answer:
LuckyWell [14K]3 years ago
6 0

Methods are collections of named code blocks, that are executed when called or evoked.

<h3>The isSorted method</h3>

The isSorted method written in Java, where comments are used to explain each line is as follows

//This defines the isSorted method

   public static boolean isSorted(double[] myArr){

       //This iterates through the array

       for (int i = 0; i < myArr.length - 1; i++){

           //If the current element is greater than the next

           if (myArr[i] > myArr[i + 1]) {

               //This returns false

               return false;

           }

       }

       //This returns true, if the array is sorted

       return true;

   }

Read more about methods at:

brainly.com/question/19360941

You might be interested in
Which of these is an example of rebranding ?
suter [353]
What are the options
7 0
3 years ago
Read 2 more answers
When making any change to the database structure, we may need to check for effects of the change on ________.?
IrinaVladis [17]
Data, foreign keys, constraints & triggers .
7 0
4 years ago
When you use filter by form to restrict records that appear, you create the filter and then click the ____ button to apply the f
AlexFokin [52]
<span>When you use filter by form to restrict records that appear, you create the filter and then click the Toggle Filter button to apply the filter.
</span><span>This button is located in the Sort & Filter group on the Home tab.
</span><span>The Toggle Filter is used to switch between the filtered and unfiltered views.</span>
4 0
3 years ago
Which would be the best reason to consider using plain tables instead of shaded tables in a document?
Eva8 [605]
The best reason to consider using plain tables instead of shaded tables in a document if the document will be copied frequently. The shaded table will  be copied exactly as shaded, and time will be wasted unshading (converting shaded table to plain table) them.  
3 0
4 years ago
Read 2 more answers
When preparing images to be used for different mediums print web and video in photoshop different file formats are required , se
Anika [276]
The answers are :
JPEG - Compresses well without losing quality, it should be used for the web
TIFF - Can be saved in an uncompressed file format with a high resolution, it is a common file format used for professional print services
BMP - Can be saved in a compressed or uncompressed file format, It is a common file format used for either web or print
<span>FLV or SWF - Used to publish a rendered video for use on the web</span>
5 0
3 years ago
Other questions:
  • Connie decided that her paper should be organized in the order in which the events happened. What type of organizational method
    15·1 answer
  • WHAT is the USE OF RIBBON TAB​
    10·1 answer
  • Garrett wants to search through a csv file to find all rows that have either the name John or Bob in them and display them out t
    9·1 answer
  • Which step of the laser printer imaging process requires troubleshooting if a printer produces ghost images on output pages?
    13·1 answer
  • Write a recursive method int power(int i, int j which determines teh result of i^j where j&gt;=0
    6·1 answer
  • which statement is true? O A Future games will be more context oriented. OB. Future games will be more product driven. Future ga
    13·2 answers
  • How do operating system work?
    5·1 answer
  • The process of identifying and removing logical errors and runtime errors is called ..............
    5·2 answers
  • Differences between formula and function as used in spreadsheet​
    13·1 answer
  • What do the last two steps in the cyclical design process most likely involve
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!