Question

In: Computer Science

Software Decode: Write a function that accepts an in-order array of unsigned integer values. The function...

  1. Software Decode: Write a function that accepts an in-order array of unsigned integer values. The function shall then scan the array for a specific pattern: Three values contained within the array equally spaced 20 units apart. The function shall return the index position within the original array where the pattern begins or -1 if not present.

    Given the input array: data[] = {10,20,31,40,55,60,65525} The function shall return: 1

IN JAVA PLEASE

Solutions

Expert Solution

public class TwentUnits {
   public static void main(String[] args) {
       int data[] = { 10, 20, 3, 40, 55, 60, 65525 };
       System.out.println(findIt(data));
   }

   private static int findIt(int[] arr) {
       // using nested loops to iterate all elements
       for (int i = 0; i < arr.length - 2; i++) {
           int sum = 0;
           // iterating 3 set of elemtns
           for (int j = i; j < i + 2; j++) {
               // finding the difference
               sum += Math.abs(arr[j] - arr[j + 1]);
           }
           // checking if it equals 20 than return i
           if (sum == 20)
               return i;
       }
       return -1;
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0....
Write a python function that accepts two integer values corresponding to the point (x, y). Check...
Write a python function that accepts two integer values corresponding to the point (x, y). Check whether the point is within the rectangle centered at (0, 0) with width 20 and height 15. For example, (-9, 7) is inside the rectangle and (11, 4) is outside the rectangle, as shown in the figure. Return True if the point falls within the rectangle and False otherwise
1) Write a function searchValue that accepts an array of integers, the size of the array,...
1) Write a function searchValue that accepts an array of integers, the size of the array, and an integer. Find the last occurrence of the integer passed in as an input argument in the array. Return the index of the last occurrence of the value. If the value is not found, return a -1 2) Write the line of code to call the previous function assuming you have an array vec with length n, and are looking for the number...
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
In c++ Array expander Write a function that accepts an int array and the arrays size...
In c++ Array expander Write a function that accepts an int array and the arrays size as arguments. The function should create a new array that is twice the size of the argument array. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a...
Write a function that accepts an int array and the array's size as arguments.
Write a function that accepts an int array and the array's size as arguments. The function should create a copy of the array, except that the element values should be reversed int the copy. The function should return a pointer to the new array. Demonstrate the function in a complete program.  
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Use of any built in string functions or built in array functions is not allowed, Any help would be much appreciated
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size...
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file...
In c++ Write a function that: accepts a string and an integer as it's only arguments...
In c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT