Untitled
unknown
plain_text
a year ago
1.0 kB
11
Indexable
public class Basics {
public static void butterfly(int n ){
int total_number_of_lines = 2*n ;
int stars = 1 ;
int spaces = 2*n-1;
int current_number_of_lines = 1 ;
while (current_number_of_lines<=total_number_of_lines) {
// stars
for(int i = 1 ; i <= stars ; i++){
System.out.print("* ");
}
//spaces
for(int i = 1 ; i <= spaces ; i++){
System.out.print(" ");
}
//stars
for(int i = 1 ; i <= stars ; i++){
System.out.print("* ");
}
System.out.println();
if (current_number_of_lines < n ) {
stars++;
spaces = spaces - 2;
} else {
stars--;
spaces = spaces + 2;
}
current_number_of_lines++;
}
}
public static void main(String[] args) {
butterfly(5);
}}Editor is loading...
Leave a Comment