Q:

Java pattern using for loop, stuck in the last part

Here is my code, I am trying to get a specific pattern but I ended up with an unexpected pattern.
for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < i * 2; j++)
        {
            if (i != 3)
            {
                System.out.print(" ");
            }
            else
            {
                System.out.print("*");
            }
        }

        for(int k = 13; k > i * 2; k--)
        {   
            System.out.print("*");  
        }

        System.out.println();
    }

I am getting this: 
*************
  ***********
    *********
*************
        *****

When I should be getting this:
*************
  ***********
    *********
  ***********
*************

Anyone can help me with this one? Thanks!

A:

The line that you print is a sequence of space '' and asterisks '*' characters. Its length is always 13. So the sum of of spaces and stars must be 13.
Whenever a line is printed 2 spaces are added to the line and 2 stars are removed, until you reach a point where the reverse operation is happened (the point is 9 stars).
This code prints that pattern.
public class Pattern{

    private static final int MAX_LINE_LENGTH = 13;
    private static final int MIN_LINE_LENGTH = 9;
    private static final int DIFFERENCE = 2;
    private static final int LINES = 5;

    private static final String SPACE = " ";
    private static final String STAR = "*";

    public static void main(String[] args) {
        printPattern();
    }

    private static void printPattern(){
        int spaces = 0;
        int stars = MAX_LINE_LENGTH;
        boolean reverse = false;

        for (int i=0; i<LINES; i++) {
            printLine(spaces,stars);

            if (stars == MIN_LINE_LENGTH) {
                reverse = true;
            }

            if (reverse == false) {
                spaces+=DIFFERENCE;
                stars-=DIFFERENCE;  
            }else{
                spaces-=DIFFERENCE;
                stars+=DIFFERENCE;
            }       
        }
    }

    private static void printLine(int spaces, int stars){
        StringBuilder builder = new StringBuilder();
        for (int i=0; i<spaces+stars; i++) {
            if (i<spaces) {
                builder.append(SPACE);      
            }else{
                builder.append(STAR);               
            }
        }
        System.out.println(builder.toString());
    }
}

