221k views
0 votes
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++)


User Prisco
by
4.7k points

1 Answer

1 vote

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) //Taken from the question.

Step-by-step 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.
User Shahjahan Jewel
by
5.4k points