How many lines does the following code output?
import java.util.*; public class Main { public static void main(String[] args) { List<String> l = Arrays.asList("A", "B"); for (String e1 : l) for (String e2 : l) System.out.print(e1 + " " + e2); System.out.println(); } // w ww. jav a2 s . co m }
A.
Looping through the same list multiple times is allowed.
There are not braces around the loops.
This means that only the print statement is inside the loop.
It executes four times.
The println()
only executes once at the end, making Option A the answer.