Ask Question
20 August, 20:22

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.

+4
Answers (1)
  1. 21 August, 00:10
    0
    The code to this question can be given as:

    Code:

    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;

    isAMember=false;

    //assign value

    for (k=0; k
    //loop

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

    {

    isAMember=true;

    //change value to true.

    break;

    //break loop

    }

    Explanation:

    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?
Not Sure About the Answer?
Find an answer to your question ✅ “In JAVA, Given:-an int variable k,-an int array currentMembers that has been declared and initialized,-an int variable memberID that has ...” 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