Why is displayed 9 times?

public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { System.out.println("Итак.."); } } } 
  • five
    @Zein, and how much should? - Nofate
  • four
    Well ... Uh-uh ... Because three times three equals nine ... - Yuriy SPb
  • four
    The cap will not leave anyone in trouble, and therefore hurries to say that this is all because 3 * 3 = 9 - DreamChild
  • 3
    So .. So .. So .. So .. So .. So .. So .. So .. So .. So .. So .. - Gorets

2 answers 2

i starts at 0 and ends at 2 (because at 3 the condition i <3 is already violated). Those. total i takes 3 values.

Similarly for j. 3x3 = 9.

    • i = 0:
      1. j = 0
      2. j = 1
      3. j = 2
    • i = 1:
      1. j = 0
      2. j = 1
      3. j = 2
    • i = 2:
      1. j = 0
      2. j = 1
      3. j = 2

    TOTAL: 9 times