File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
src/main/java/com/thealgorithms/strings/zigZagPattern Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .company .basic ;
2+
3+ import java .util .*;
4+
5+
6+ public class Prac1 {
7+ public static void main (String [] args ) {
8+ Scanner scan =new Scanner (System .in );
9+ int n =scan .nextInt ();
10+ for (int i =1 ;i <=n ;i ++) {
11+ for (int a =1 ;a <=i ;a ++) {
12+ if (a == 1 || a == i ) {
13+ System .out .print ("*" );
14+ } else {
15+ System .out .print (" " );
16+ }
17+ }
18+ for (int s =1 ;s <=2 *(n -i );s ++) {
19+ System .out .print (" " );
20+ }
21+ for (int a =1 ;a <=i ;a ++) {
22+ if (a == 1 || a == i ) {
23+ System .out .print ("*" );
24+ } else {
25+ System .out .print (" " );
26+ }
27+ }
28+ System .out .println ();
29+ }
30+ // Lower Part-
31+ for (int i =n ;i >0 ;i --) {
32+ for (int a =1 ;a <=i ;a ++) {
33+ if (a == 1 || a == i ) {
34+ System .out .print ("*" );
35+ } else {
36+ System .out .print (" " );
37+ }
38+ }
39+ for (int s =1 ;s <=2 *(n -i );s ++) {
40+ System .out .print (" " );
41+ }
42+ for (int a =1 ;a <=i ;a ++) {
43+ if (a == 1 || a == i ) {
44+ System .out .print ("*" );
45+ } else {
46+ System .out .print (" " );
47+ }
48+ }
49+ System .out .println ();
50+ }
You can’t perform that action at this time.
0 commit comments