I could not figure it out. | Sololearn: Learn to code for FREE!

+1

I could not figure it out.

how this works. public class Program { public static void main(String[] args) { int i,j; for(i=1;i<4;i++){ for(j=1;j<2;j++){ System.out.println("v"); System.out.println("8"); } } } }

6/23/2018 7:03:48 PM

stephen haokip

4 Answers

New Answer

+11

first loop is execute 3 time for i=1,2,3 and second for loop is execute one time because 1<2 so only one time condition true and loop body executed so for i = 1 the inner loop print v,8 for i = 2 the inner loop print v,8 for i = 3 the inner loop print v,8 so output came as v 8 v 8 v 8

+7

I don’t know exactly what you want, but it’s basically two loops, one inside the other, or nested, printing out v and 8. if the first for statement is true, it moves to the second for statement, which prints the v and 8 out.

+2

thank q pal

+2

In this code there are two nested for loops. First the inner loop iterates, after the loop ends the outer loop is iterating one time and again the inner loop starts.You can read more here https://study.com/academy/lesson/nested-for-loops-in-java.html