Let's roll out the ifs, recursion and the loop. What the system does its:
print(i=4) { System.out.print("Y") -> Y print(i=3) { System.out.print("Y") -> YY print(i=2){ System.out.print("Y") -> YYY print(i=1){ //skip if and print 1x i=1 System.out.print(1) -> YYY1 } //print 2x i=2 System.out.print(2) -> YYY12 System.out.print(2) -> YYY122 } //print 3x i=3 System.out.print(3) -> YYY1223 System.out.print(3) -> YYY12233 System.out.print(3) -> YYY122333 } //print 4x i=4 System.out.print(4) -> YYY1223334 System.out.print(4) -> YYY12233344 System.out.print(4) -> YYY122333444 System.out.print(4) -> YYY1223334444 } The code deos not return after the if but execute the for loop.
If you're new to Java, make yourself familiar with a debugger, which allesallows a step-by-step execution and value introspection and is part of every Java IDE