Given : an int variable k, an int array currentMembers that has been declared and initialized, an int variable nMembers that contains the number of elements in the array, an int variable memberID that has been initialized, and a bool variable isAMember. Write 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, nMembers, and isAMember .

Respuesta :

Limosa

Answer:

The following are the code in the Java Programming Language.

//set the for loop

for (k = 0; k < nMembers; k++)

{

//check that currentMembers[k] is equal to the memberID

if (currentMembers[k] == memberID)

{

//then, initialize isAMember to true

isAMember = true;

//and initialize the value of nMembers in k

k = nMembers;

}

//otherwise

else

{

//initialize isAMember to false

isAMember = false;

}

}

Explanation:

The following are the description of the program.

  • Set the for loop statement that iterates from 0 and stops at the variable 'nMembers'.
  • Set the if conditional statement that checks the variable 'currentMembers[k]' is equal to the variable 'memberID' then, initialize 'true' boolean value in the variable 'isAMember' and also initialize the value of the variable 'nMembers' in the variable 'k'.
  • Otherwise, initialize 'false' boolean value in the variable 'isAMember'.
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE