1 Square

1.1 Pattern

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

1.2 Solution

int n=5;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        System.out.print("* ");
    }
    System.out.println();
}

2 Increasing Triangle

2.1 Pattern

*
* *
* * *
* * * *
* * * * *

2.2 Solution

int n=5;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
        System.out.print("* ");
    }
    System.out.println();
}

3 Right Sided Triangle

3.1 Pattern

          *
        * *
      * * *
    * * * *
  * * * * *

3.2 Solution

int n=5;
for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
        System.out.print("  ");
    }
    for (int j = 1; j <= i; j++) {
        System.out.print("* ");
    }
    System.out.println();
}

4 Decreasing Triangle

4.1 Pattern

* * * * *
* * * *
* * *
* *
*

4.2 Solution

int n=5;
for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
        System.out.print("* ");
    }
System.out.println();
}

5 Right Sided Triangle

5.1 Pattern

  * * * * *
    * * * *
      * * *
        * *
          *

5.2 Solution

int n=5;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
        System.out.print("  ");
    }
    for (int j = i; j <= n; j++) {
        System.out.print("* ");
    }
System.out.println();
}