Ask Question
13 October, 18:18

In JAVA, Given:-an int variable k,-an int array currentMembers that has been declared and initialized,-an int variable memberID that has been initialized,-and an boolean variable isAMember, write a code that assigns true to isAMember if the value of memberID can be found in currentMembers, and that assigns false to isAMember otherwise. Use only k, currentMembers, memberID, and isAMember.

Answers (1)
  1. 13 October, 19:42
    The code to this question can be given as:


    int k; / /declare integer variable k

    //declared array and initialized array

    int currentMembers[]={1,2,3,4,5,9,6,7};

    //declared integer variable memberID.

    int memberID=9;

    //declared boolean variable isAMember

    boolean isAMember;


    //assign value

    for (k=0; k

    if (currentMembers[k] = = memberID) / /check condition



    //change value to true.


    //break loop



    In the above code firstly we declare the integer variables that name is already given in the question that is k and memberID in this variable we assign value. Then we declare an array variable currentMembers and initialized values in array. Then we declare a Boolean variable isAMember. This variable is used to assign only true or false value. Then we declare a for loop. loop is used to check all array elements. In this loop, we use the if condition in the if block if the array element matches with memberID. It breaks the condition and end of the loop.
Know the Answer?