Answer:
Following are the code to the given question:
int j,chocolateFlavorCount = 0;//declaring integer vvariable
for(j=0;j< flavorArray.length;j++)//defining a loop that starts from 1 to array length
{
if(flavorArray[i].contains("chocolate"))//use if that checks array contains string value that is chocolate
{
chocolateFlavorCount++;//incrementing integer variable value
}
}
System.out.println(chocolateFlavorCount);//printing integer variable
Step-by-step explanation:
- In this question, an integer variable "chocolateFlavorCount, and j" is declared, in which j used in the for loop.
- The loop starts from 1 and stops when it is equal to the array length it also defines an if block that checks array contains string value that is chocolate.
- If the condition is true it will increment integer variable value and print its values.