NEW
Font size
S
M
L
XL
Worksheetsfor-each loop + java
Total questions: 80
Worksheet time: 27mins
Name
Class
Date
1.
What is the name of the loop that is used to iterate over the names array in the Java code snippet in the image?
a)
for loop
b)
while loop
c)
do-while loop
d)
for-each loop
2.
What is the variable that is used to store the current element in the for-each loop in the image?
a)
i
b)
name
c)
array
d)
loop
3.
What is the name of the collection that is used in the for-each loop in the image?
a)
names
b)
numbers
c)
stream
d)
array
4.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
i
b)
arr
c)
element
d)
index
5.
What is the variable name that is used to store the current element in the for-each loop in the image?
a)
i
b)
array
c)
num
d)
element
6.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
listofNames
c)
i
d)
array
7.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
String
b)
ArrayList
c)
int
d)
Integer
8.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
int
b)
String
c)
char
d)
double
9.
What is the name of the array that is used in the for-each loop in the image?
a)
names
b)
nums
c)
array
d)
list
10.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
array
c)
index
d)
counter
11.
What is the name of the loop that is used to iterate over the elements of the array in the image?
a)
for loop
b)
while loop
c)
do-while loop
d)
for-each loop
12.
What is the error message that is displayed in the image?
a)
for-each not applicable to expression type required: array or java.lang.Iterable found: String
b)
for-each loop cannot be used with String
c)
for-each loop cannot be used with arrays
d)
for-each loop cannot be used with collections
13.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
14.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
seq
c)
element
d)
index
15.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
String
b)
int
c)
char
d)
double
16.
What is the name of the collection that is used in the for-each loop in the image?
a)
names
b)
list
c)
students
d)
array
17.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
String
b)
int
c)
char
d)
double
18.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
array
d)
index
19.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
20.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
int
b)
String
c)
char
d)
double
21.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
stuname
c)
id
d)
marks
22.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
23.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
24.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
int
b)
String
c)
char
d)
double
25.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
26.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
27.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
28.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
29.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
Answer Choices:
b)
int
c)
char
d)
double
30.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
31.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
list
32.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
33.
What is the name of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
list
34.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
35.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
36.
What is the type of the collection that is used in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
37.
What is the type of the variable that is used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
38.
What is the name of the loop control variable in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
39.
What is the type of the collection that is being iterated over in the for-each loop in the image?
a)
ArrayList
b)
LinkedList
c)
HashSet
d)
HashMap
40.
What is the type of the variable that is being used to store the current element in the for-each loop in the image?
a)
name
b)
num
c)
index
d)
array
41.
What is the purpose of the next element check in the for-each loop?
a)
To check if there are more elements in the list.
b)
To get the next element in the list.
c)
To exit the loop if there are no more elements in the list.
d)
To iterate through the list in reverse order.
42.
What is the data type of the variable listNumber in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
43.
What is the variable name used to store the current element in the for-each loop?
a)
listNumber
b)
element
c)
nextElement
d)
arrayNumber
44.
Which of the following is a benefit of using the for-each loop over the traditional for loop in Java?
a)
It is shorter and easier to read.
b)
It can be used to iterate over any collection, not just arrays.
c)
It does not require the use of an index variable.
d)
It is more efficient.
45.
What is the name of the variable used to store each element of the array in the for-each loop?
a)
listNumber
b)
element
c)
nextElement
d)
arrayNumber
46.
What is the data type of the variable name in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
47.
What is the purpose of the Enumerator field in the for-each loop editor?
a)
To specify the type of collection that will be iterated over.
b)
To get the next element in the collection.
c)
To exit the loop if there are no more elements in the collection.
d)
To iterate through the collection in reverse order.
48.
What is the name of the variable that is used to store each element of the collection in the for-each loop?
a)
element
b)
nextElement
c)
arrayNumber
d)
listNumber
49.
What is the purpose of the next element check in the flow chart?
a)
To check if there are more elements in the collection.
b)
To get the next element in the collection.
c)
To exit the loop if there are no more elements in the collection.
d)
To iterate through the collection in reverse order.
50.
Which of the following statements will cause the for-each loop to exit immediately?
a)
return;
b)
break;
c)
continue;
d)
exit;
51.
What is the name of the variable that is used to store each element of the array in the for-each loop?
a)
element
b)
nextElement
c)
arrayNumber
d)
listNumber
52.
What is the benefit of using a for-each loop over a traditional for loop to iterate over an array of integers?
a)
It is shorter and easier to read.
b)
It does not require the use of an index variable.
c)
It is more efficient.
d)
It can be used to iterate over any collection, not just arrays.
53.
What is the type of the variable name in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
54.
What is the purpose of the element variable in the for-each loop?
a)
To store the current element in the array.
b)
To iterate over the array.
c)
To get the next element in the array.
d)
To exit the loop if there are no more elements in the array.
55.
What is the name of the collection that is being iterated over in the for-each loop?
a)
numbers
b)
list
c)
array
d)
collection
56.
What is the data type of the variable number in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
57.
What is the purpose of the next element check in the for-each loop?
a)
To check if there are more elements in the collection.
b)
To get the next element in the collection.
c)
To exit the loop if there are no more elements in the collection.
d)
To iterate through the collection in reverse order.
58.
What is the name of the variable that is used to store each element of the collection in the for-each loop?
a)
element
b)
nextElement
c)
arrayNumber
d)
listNumber
59.
What is the purpose of the for loop in the image?
a)
To iterate over the array of integers.
b)
To print the array of integers.
c)
To store the array of integers in a variable.
d)
To check if the array is empty.
60.
What is the name of the collection that is being iterated over in the for-each loop?
a)
numbers
b)
list
c)
array
d)
collection
61.
What is the data type of the variable element in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
62.
What is the purpose of the break statement in the for-each loop?
a)
To exit the for-each loop immediately.
b)
To skip the current iteration of the for-each loop.
c)
To iterate through the collection in reverse order.
d)
To print the current element of the collection to the console.
63.
What is the purpose of the continue statement in the for-each loop?
a)
To exit the for-each loop immediately.
b)
To skip the current iteration of the for-each loop.
c)
To iterate through the collection in reverse order.
d)
To print the current element of the collection to the console.
64.
What is the purpose of the if statement in the for-each loop?
a)
To check if the current element of the collection is equal to 5.
b)
To exit the for-each loop immediately.
c)
To skip the current iteration of the for-each loop.
d)
To iterate through the collection in reverse order.
65.
What is the purpose of the variable element in the for-each loop?
a)
To store the current element of the collection.
b)
To iterate over the collection.
c)
To get the next element of the collection.
d)
To exit the loop if there are no more elements in the collection.
66.
What is the data type of the variable name in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
67.
What is the purpose of the for loop in the image?
a)
To iterate over the array of strings.
b)
To print the array of strings.
c)
To store the array of strings in a variable.
d)
To check if the array is empty.
68.
What is the name of the collection that is being iterated over in the for-each loop?
a)
names
b)
list
c)
array
d)
collection
69.
What is the purpose of the continue statement in the for-each loop?
a)
To exit the for-each loop immediately.
b)
To skip the current iteration of the for-each loop.
c)
To iterate through the collection in reverse order.
d)
To print the current element of the collection to the console.
70.
What is the purpose of the if statement in the for-each loop?
a)
To check if the current element of the collection is equal to 5.
b)
To exit the for-each loop immediately.
c)
To skip the current iteration of the for-each loop.
d)
To iterate through the collection in reverse order.
71.
What is the purpose of the variable element in the for-each loop?
a)
To store the current element of the collection.
b)
To iterate over the collection.
c)
To get the next element of the collection.
d)
To exit the loop if there are no more elements in the collection.
72.
What is the data type of the variable number in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
73.
What is the purpose of the break statement in the for-each loop?
a)
To exit the for-each loop immediately.
b)
To skip the current iteration of the for-each loop.
c)
To iterate through the collection in reverse order.
d)
To print the current element of the collection to the console.
74.
What is the name of the collection that is being iterated over in the for-each loop?
a)
numbers
b)
list
c)
array
d)
collection
75.
What is the purpose of the variable number in the for-each loop?
a)
To store the current element of the collection.
b)
To iterate over the collection.
c)
To get the next element of the collection.
d)
To exit the loop if there are no more elements in the collection.
76.
What is the purpose of the continue statement in the for-each loop?
a)
To exit the for-each loop immediately.
b)
To skip the current iteration of the for-each loop.
c)
To iterate through the collection in reverse order.
d)
To print the current element of the collection to the console.
77.
What is the purpose of the if statement in the for-each loop?
a)
To skip the current iteration of the for-each loop if the current element is equal to 5.
b)
To exit the for-each loop immediately if the current element is equal to 5.
c)
To iterate through the collection in reverse order if the current element is equal to 5.
d)
To print the current element of the collection to the console if the current element is equal to 5.
78.
What is the purpose of the for loop in the image?
a)
To iterate over the array of strings.
b)
To print the array of strings.
c)
To store the array of strings in a variable.
d)
To check if the array is empty.
79.
What is the data type of the variable name in the for-each loop?
a)
int
b)
String
c)
List
d)
Object
80.
What is the name of the collection that is being iterated over in the for-each loop?
a)
names
b)
list
c)
array
d)
collection
Reset
