Competitive Programming Solutions

GitHub
back to dashboard

W. Shape3

Codeforces - Sheet #2 (Loops) · limit: 1s · memory: 256MB · view on codeforces

input

4

output

   *
  ***
 *****
*******
*******
 *****
  ***
   *
Main.java
static void solve() {

        // Write your solution here
        int n = in.nextInt();
        int i = 1;
        while (i <= n) {
            int j = 1;
            while (j++ <= n - i)
                out.print(" ");
            j = 1;
            while (j++ <= i * 2 - 1)
                out.print("*");
            out.println();
            i++;
        }
        i--;
        while (i > 0) {
            int j = 1;
            while (j++ <= n - i)
                out.print(" ");
            j = 1;
            while (j++ <= i * 2 - 1)
                out.print("*");
            out.println();
            i--;
        }
    }