diff --git a/pattern b/pattern new file mode 100644 index 0000000..2745484 --- /dev/null +++ b/pattern @@ -0,0 +1,38 @@ + +import java.util.Scanner; + +public class pattern { + public static void main(String[] args) { + Scanner scn = new Scanner(System.in); + int N = scn.nextInt(); + + int nst = 1; + int nsp = 2 * N - 3; + + for (int row = 1; row <= N; row++) { + for (int cst = 1; cst <= nst; cst++) { + + System.out.print("*"); + } + for (int csp = 1; csp <= nsp; csp++) { + System.out.print(" "); + } + int cst; + if (row == N) { + cst = 2; + + } else { + cst = 1; + } + + for (; cst <= nst; cst++) { + System.out.print("*"); + + } + System.out.println(); + nst++; + nsp -= 2; + } + + } +}