An array of Strings, names, has been declared and initialized. Write the statements needed to determine whether any of the array elements are null or refer to the empty String. Set the variable hasEmpty to true if any elements are null or empty-- otherwise set it to false.
This is the code I put in, but it has compile errors
hasEmpty = false;
int k = 0;
for (k = 0; k < names.length; k++)
{
if ((names[k] == null) || (names[k].equals("")))
hasEmpty = true;
}

Respuesta :

Answer:

boolean hasEmpty = false; //This is line which have compile time error and which is modified.

int k = 0; //Taken from the question.

for (k = 0; k < names.length; k++)// Taken from the question.

           {//Taken from the question

               if ((names[k] == null) || (names[k].equals("")))//Take from the question.

                hasEmpty = true; //taken from the question.

              }//Taken from the question.

Explanation:

  • There is one line which gives the compile-time error and that is in the "hasEmpty = false;" statement because there is no any data type defined for this value, so when we write the code in the java language, then we need to define it like " boolean hasEmpty = false; ".
  • The above answer is in java language because there are "names.length" which is used in java and the string data type is also used in java which is defined in the question.