Ask Question
21 June, 18:57

Write a static method named contains that accepts two arrays of integers a1 and a2 as

parameters and that returns a boolean value indicating whether or not a2's sequence of

elements appears in a1 (true for yes, false for no). The sequence of elements in a2 may

appear anywhere in a1 but must appear consecutively and in the same order. For example, if

variables called list1 and list2 store the following values:

int[] list1 = {1, 6, 2, 1, 4, 1, 2, 1, 8};

int[] list2 = {1, 2, 1};

Then the call of contains (list1, list2) should return true because list2's sequence of

values {1, 2, 1} is contained in list1 starting at index 5. If list2 had stored the values {2,

1, 2}, the call of contains (list1, list2) would return false because list1 does not

contain that sequence of values. Any two lists with identical elements are considered to contain

each other, so a call such as contains (list1, list1) should return true.

+1
Answers (1)
  1. 21 June, 22:51
    0
    Sew explaination foe code

    Explanation:

    import java. lang.*;

    import java. util.*;

    import java. io.*;

    class Main

    {

    public static Boolean checkSubset (int[] list1, int[] list2)

    {

    int l = list2. length;

    for (int i = 0; i
    {

    Boolean flag = true;

    for (int j = 0; j
    {

    if (list1[i+j]! = list2[j])

    {

    flag = false;

    break;

    }

    }

    if (flag) return true;

    }

    return false;

    }

    public static void main (String args[])

    {

    int[] l1 = {1,6,2,1,4,1,2,1,8};

    int[] l2 = {1,2,2};

    System. out. println (checkSubset (l1, l2));

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a static method named contains that accepts two arrays of integers a1 and a2 as parameters and that returns a boolean value ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers