22.5k views
1 vote
What is the output of the following code: ​ for (loop = 1; loop <3; ++loop) System.out.print(1); for (loop2 = 1; loop2<3; ++loop2) System.out.print(2); ​

1 Answer

6 votes

Answer:

The output of the given code as follows:

Output:

1122

Explanation:

In the given java code the two for loop is defined, which can be described as follows:

  • In the first loop, a"loop" variable is used, which starts from 1 and ends when the value of loop is less than 3, inside the loop a print function is used, that print value 1.
  • In the next step, another for loop is declared, inside the loop a variable "loop2" variable is used, that's working is the same as the above loop, but in this loop, it will print a value, that is 2.
User Kasium
by
4.7k points