Fill in the blanks for the each loop so we can print the con
Solution
Please follow the code and comments for description :
CODE :
class ForEachEx{
public static void main(String args[]){ // driver method
int arr[]={12,13,14,44}; // sample array
for(int i:arr){ // for each loop of the data
System.out.println(i); // print to console
}
}
}
OUTPUT :
12
13
14
44
In the same way for the give code as the array list a string type, the varaible in the for-each loop for the code needs to be of a string type so the blanks in the code are to be replaced as :
for(String name : list) {
System.out.println(name);
}
Description :
The above code has the initialisation of the variable named name and of the type String datatype for each of the data in the array list named list. The each data saved in the variable name is to be printed so the console data for the next line is to be placed as the variable as name.
Hope this is helpful
