MCPcopy Create free account
hub / github.com/apna-college/Alpha / butterfly

Method butterfly

0_JavaProgrammingBasics/Patterns/Patterns.java:68–108  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

66 }
67
68 public static void butterfly(int n) {
69 //1st half
70 for(int i=1; i<=n; i++) {
71 //stars
72 for(int j=1; j<=i; j++) {
73 System.out.print("*");
74 }
75
76 //spaces
77 for(int j=1; j<=2*(n-i); j++) {
78 System.out.print(" ");
79 }
80
81 //stars
82 for(int j=1; j<=i; j++) {
83 System.out.print("*");
84 }
85
86 System.out.println();
87 }
88
89 //2nd half
90 for(int i=n; i>=1; i--) {
91 //stars
92 for(int j=1; j<=i; j++) {
93 System.out.print("*");
94 }
95
96 //spaces
97 for(int j=1; j<=2*(n-i); j++) {
98 System.out.print(" ");
99 }
100
101 //stars
102 for(int j=1; j<=i; j++) {
103 System.out.print("*");
104 }
105
106 System.out.println();
107 }
108 }
109
110 public static void solid_rhombus(int n) {
111 for(int i=1; i<=n; i++) {

Callers 1

mainMethod · 0.95

Calls 1

printMethod · 0.45

Tested by

no test coverage detected