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
How many types of string types does python support?​
Andru [333]

Answer:

47

Explanation:

they support all of them,more their babies and offspring

7 0
4 years ago
Can someone urgently help me with my java code? Ive been working on it for hours and its not working.
Paha777 [63]

Answer:

nm hn hhjjnjjnj j

Explanation:

kjnjnjn jnjubhvcfv

3 0
3 years ago
A network technician is setting up a web server for a small company. The company has obtained a domain name, company-a, from a d
Alja [10]

Answer:

There is Name resolution failure

Explanation:

This normally occurs when the computer can't access the host (your server). It can be caused by several factors, such as:

-Internet connectivity is down

-The client does not have DNS servers configured or is configured with the incorrect DNS server IP addresses.

-The DNS servers are failing.

3 0
4 years ago
To be eligible for the leadership training program offered by the office, a student must have at least 2 years of post-secondary
erica [24]

Answer:

The formula for the given problem is:

=IF(OR(D2>=2,G2>"Yes"), "Yes", "No")

Explanation:

Please see attachment for step by step guide

7 0
4 years ago
The Hazard Communication Standard, commonly called the “Right-to-Know” law, gives you the right to know what information?
statuscvo [17]
Lets you know if their are any certain hazards or messes on the property like mold or ants
8 0
3 years ago
Other questions:
  • A form of artificial intelligence that can perform many complex, _______ tasks. Select one: a. serialized b. repetitive c. non-r
    7·1 answer
  • Write a function that, given an array of integers and its size, reverses the elements in the array. For example, if the original
    13·1 answer
  • A(n) ____ allows others besides the manufacturer to develop software to run on the system or device.
    14·1 answer
  • Define foreign key. What is this concept used for?
    6·1 answer
  • True or false Encryption prevents hackers from hacking data?
    8·1 answer
  • Task 1: Alex has created the following code using Scratch and expected it to move backwards and forwards across the screen. Howe
    13·1 answer
  • Complete the program below named CountVowels so that it reads in a string, counts all the vowels in that string, and prints out
    13·1 answer
  • 1. Which of the following is not a question that should be asked when planning a Windows Server 2019 installation?
    13·1 answer
  • to see additional functions available in an open desktop, document or website what action should the user perform?
    11·2 answers
  • Tristan just downloaded a new game he wants to play on his computer. What kind of file should he open in order to install and ru
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!