Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.0 kB
2
Indexable
Never
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);
}}
Leave a Comment