/**
* Write a method named outOfOrder that takes as a parameter an
array of double and returns a value of type int.
* This method will test the array for being out of order, meaning
that the array violates the conditions:
* array[0] <= arrayValues[0] <= arrayValues[2] <=...
*
* The method returns -1 if the elemnts are not out of order;
otherwise , it returns the index of the first element of the array
that is out of order.
* For example, consider the declaration:
* double[] arrayValues = {1.2, 2.1, 3.3, 4.5, 2.5, 7.9, 5.4, 8.7,
9.9, 1.5};
* In the array above, array[3] and arrayValues[4] are the first
pair out of order, and arrayValues[4] is the frist element out of
order, so the method returns 5.
* If the array were sorted, the method would return -1.
*/
public static void runProblem1()
{
double[] unSortedArray = {1.2, 2.1, 3.3, 4.5, 2.5, 7.9, 5.4, 8.7,
9.9, 1.5};
double[] sortedArray = {1.3, 2.9, 3.4, 4.6, 6.8, 7.5, 10.1, 12.6,
45.9, 50.6, 63.7};
System.out.println("The method will take in an array and evaluate
if it is sorted:\nReturn of -1 means it is sorted, any other value
will indicate the index that is out of order");
System.out.println("The unsorted Array result: "+
outOfOrder(unSortedArray));
System.out.println("The sorted Array result: "+
outOfOrder(sortedArray));
}
Answer:
Explanation:
For loop is used to traverse the array. If any element is greater than its next element, position of next element is returned. Otherwise at the end, -1 is returned.

COde:
public static int outOfOrder(double[] a)
{
for(int i=0; i<a.length-1; i++)
{
if(a[i]>a[i+1])
{
return i+2;
}
}
return -1;
}
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
/** * Write a method named outOfOrder that takes as a parameter an array of double...
1. Write a static method named mode that takes an array of integers as a parameter and that returns the value that occurs most frequently in the array. Assume that the integers in the array appear in sorted order. For example, if a variable called list stores the following values: ist -3, 1, 4, 4, 4, 6, 7,8, 8, 8, 8, 9, 11, 11, 11, 12, 14, int 141i Then the call of mode (li array, appearing four times. st,...
Write a method named avgLength which takes an array of Strings as an input parameter and returns a double. The method should calculate and return the average length of all the strings in the array (in java langauge)
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
Please Write in Java An array is sorted (in ascending order) if each element of the array is less than or equal to the next element . An array of size 0 or 1 is sorted Compare the first two elements of the array ; if they are out of order, the array is not sorted; otherwise, check the if the rest of the array is sorted. Write a boolean -valued method named isSorted that accepts an integer array , and the number of...
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
write in java 1. Assume the availability of a method named makeLine that can be passed a non-negative integer n and a character c and return a String consisting of n identical characters that are all equal to c. Write a method named printTriangle that receives two integer parameters n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...
Write a static method that takes an array of Strings and returns a double. Determine the average number of characters for the Strings assigned to the array. Return the average.
Write a method named RandomDoubles that takes a parameter N as its argument and generates N random double values where each double value is a random double between 0.0 and 0.9999…. (i.e. simply use Math.random()) and save these double values into a file named doubles.txt.(java please) Next, write the following method that returns the number of digits in the fractional part of a double value. For example, 12.345 has 3 digits in the fractional part, 1.2345 has 4 digits in...
Write a C++ function binsearch that carries out the binary search algorithm on a sorted array of integers. Your function takes as parameters an array of integers (sorted in increasing order), the size of the array, and a target integer to search for. The function returns the index of the target in the array, and returns -1 if the target is not in the array. The file main1.txt on the webpage contains code that generates a specific array of integers...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...