Skip to content

Instantly share code, notes, and snippets.

@bijay-shrestha
Created July 1, 2021 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bijay-shrestha/5252c36042b4374789d110c87b0280b5 to your computer and use it in GitHub Desktop.
Save bijay-shrestha/5252c36042b4374789d110c87b0280b5 to your computer and use it in GitHub Desktop.
/**
*
* Print Nepal Flag in your console.
*/
package com.basic.practice;
public class NepalFlag {
public static void main(String[] args) {
printFlag();
printFlag();
}
static void printFlag() {
for (int i = 0; i < 5; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
@sanjmgr
Copy link

sanjmgr commented Aug 16, 2022

What about only outer layer of flag?

@sanjmgr
Copy link

sanjmgr commented Aug 16, 2022

static void printNepalFlag() {
    int col = 5;

    for (int i = 0; i <= col; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || i == j || i == col) {
                System.out.print(" * ");
            } else {
                System.out.print("   ");
            }
        }

        System.out.println("");
    }
}


/*  *
   *  *
   *     *
   *        *
   *           *
   *  *  *  *  *  *
   *
   *  *
   *     *
   *        *
   *           *
   *  *  *  *  *  *
  * */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment