Making a triangle without inner stars By this method I am able to solve my problem, but is there any other way that I can make this type of triangle? Please correct my code if I am doing this the long way.

public class Pyramid{
    public static void main(String [] args){
        for (int i=0;i&lt;= 6 ;i++) {
            for (int x=0;x &lt; 6-i;x++) {
                System.out.print(" ");
                }
                for (int k=1;k&lt;=i;k++) {
                        if (k &lt;= 1) {
                            System.out.print(" *");
                        }
                        else if(k &lt;= 2) {
                            System.out.print("  ");
                        }
                        else if(k &lt;= 3) {
                            System.out.print("  ");
                        }
                        else if(k &lt;= 4) {
                            System.out.print("  ");
                        }
                        else if(k &lt;= 5) {
                            System.out.print("  ");
                        }
                        else if(k &lt;= 6) {
                            System.out.print("  ");
                        }

                }
                for (int l=0;l&lt;=i;l++) {
                        if (l &lt;= 0) {
                            System.out.print(" *");
                        }

                }
                System.out.println();

    }   
    System.out.print("* * * * * * * *");    
}
}
Your method certainly works, but I agree that using nested/multiple loops and inner if/else blocks is inelegant, if only because it makes following the code somewhat harder. Also, as you point out in a comment, hard-coding the structure is a nightmare if you suddenly want a pyramid which is 46 stars high.

As an alternative, I've rewritten the code to break it out into separate methods which hopefully make the code easier to understand, and also to allow a variable pyramid height (any value from zero or above).

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

private static void drawStarPyramid2(int height) {
    if (height &lt; 0) {
        throw new IllegalArgumentException("Height cannot be negative.");
    }
    StringBuilder sb = new StringBuilder(height * height);
    appendSides(sb, height);
    appendBaseline(sb, height);
    System.out.println(sb.toString());
}

private static void appendSides(StringBuilder sb, int height) {
    int baselineWidth = height * 2 - 1;
    int midLine = baselineWidth / 2;
    for (int rowIndex = 0; rowIndex &lt; height - 1; ++rowIndex) {
        int leftStarOffset = midLine - rowIndex;
        appendSpacesThenStar(sb, leftStarOffset);
        if (rowIndex &gt; 0) {
            int rightStarOffset = midLine + rowIndex - 1;
            appendSpacesThenStar(sb, rightStarOffset - leftStarOffset);
        }
        sb.append("\n");
    }
}

private static void appendSpacesThenStar(StringBuilder sb, int spaces) {
    for (int spaceIndex = 0; spaceIndex &lt; spaces; ++spaceIndex) {
        sb.append(' ');
    }
    sb.append('*');
}

private static void appendBaseline(StringBuilder sb, int stars) {
    boolean first = true;
    for (int starIndex = 0; starIndex &lt; stars; ++starIndex) {
        if (!first) {
            sb.append(' ');
        }
        sb.append('*');
        first = false;
    }
}


Because the sides need to be rendered differently to the baseline, each chunk of code goes into its own method, with a name which clearly describes the different purpose of each.

The appendSides method is responsible only for drawing the left and right sides of the triangle. This calculates the baseline width (the number of characters on the console counting stars and spaces) and this will be equal to height stars (because the number of stars on the baseline must equal the number of stars along the height of each side) plus height - 1 spaces, which gives 2 * height - 1. Then it calculates the mid-way point (in terms of characters on the console line) and then places the first star at this point.

For all subsequent lines, the "left" side star is simply placed at the position which is one additional character further left of the previous position (starting at the mid-way position), and the "right" side star at the position which is one additional character further right of the previous position. The rowIndex is a convenient way to calculate how many places to move away from the mid-way point on each line. The mathematics being used to calculate all of these offsets is fairly simple, but I recommend you sketch it out on a bit of paper, one line at a time, to get a feel for how the numbers work together.

The appendSpacesThenStar method simply appends the specified number of space characters to the StringBuilder and then a star. This method does not append a newline, because this method is often called twice for the same line, to write the "left" and then the "right" stars.

The appendBaseline method just appends (to the StringBuilder) the required number of stars, separated by spaces.

A StringBuilder is being used to make assembly of the final string sequence more efficient, allowing the building of each line to be split across multiple method calls, rather than trying to finish each line in a single statement.

(Also note that the initial capacity passed to the StringBuilder constructor can be improved by giving exactly the number of characters that will be needed, once spaces, stars, and newlines have been taken into consideration, but I'll leave this as an exercise for you.)