Skip to content

Commit afd853c

Browse files
Create NewPattern.java
Added a code of butterfly pattern with hollow space in java.
1 parent bca8d0e commit afd853c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

0 commit comments

Comments
 (0)