Ask Question
29 October, 02:37

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. 29 October, 02:49
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers