...

/

Solution Review: Pyramid Printing by Using 'for' Loop

Solution Review: Pyramid Printing by Using 'for' Loop

In this review, the solution of the challenge 'Pyramid Printing by Using 'for' Loop' from the previous lesson is provided.

Solution #

Java
class HelloWorld {
public static void main( String args[] ) {
int rows = 5;
for (int i = 1; i <= rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print("# ");
}
System.out.println();
}
}
}

Explanation

Here is a breakdown of the above code for your thorough understanding.

  • for(int i = 1; i <= rows; ++i) Outer for loop to iterate till the total number of rows. The outer for ...