145k views
2 votes
What is the first and last value of i to be displayed by the following code snippet? int n = 20; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { System.out.println("" + i); } }

User Tiziano
by
5.3k points

1 Answer

4 votes

Answer:

The first value of i is 0 and last value of i is 20.

Step-by-step explanation:

The following are the description of a given loop.

  • In this problem, there are two loops one is the internal loop and the other is the external loop
  • In the outer loop, the value of " i" is initialized with "0" So the first value is printed 0 in the console.
  • For one value of "i" all the inner loop is executed.
  • The loop is executed is less equal to 20 that's why the last value of "i" is printed 20 in the console window.

User Nowa Concordia
by
5.1k points