Question: Integer numSize is read from input. ArrayList nameValues contains numSize strings read from input. Complete the enhanced for loop to add each element in nameValues

Integer numSize is read from input. ArrayList nameValues contains numSize strings read from input. Complete the enhanced for loop to add each element in nameValues that is not equal to "Mai" to filteredNamesList.
Ex: If the input is:
5
Gil Rob Mai Mai Dax
then the output is:
Names that are not Mai:
Gil Rob Dax
import java.util.Scanner;
import java.util.ArrayList;
public class Names {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
ArrayList nameValues = new ArrayList();
ArrayList filteredNamesList = new ArrayList();
int numSize;
int i;
numSize = scnr.nextInt();
for (i =0; i < numSize; ++i){
nameValues.add(scnr.next());
}
for (String nameValue : nameValues){
/* Your code goes here */
}
System.out.println("Names that are not Mai:");
for (String nameValue : filteredNamesList){
System.out.print(nameValue +"");
}
System.out.println();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!