Java Cross with characters I managed to make a perfectly even cross with for loops.

I'm trying to make this cross easier to code.  I have to keep it with for loops, but it's too long to implement.

public class CroixDemoAmmeliore {
    public static void main(String args[]) {

        int e = 5;
        int i;
        int j;
        int k;
        int l;

        for (k = 1; k &lt;= e; k++) {
            for (i = 1; i &lt;= e; i++) {
                System.out.print(" ");
            }
            for (j = 1; j &lt;= e; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (k = 1; k &lt;= e; k++) {
            for (i = 1; i &lt;= e * 3; i++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (k = 1; k &lt;= e; k++) {
            for (i = 1; i &lt;= e; i++) {
                System.out.print(" ");
            }
            for (j = 1; j &lt;= e; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
First thing I would say is that you could reduce the number of variables you use. The iterator of a For loop, if instanced from outside the loop's context (as in your case), can be reused. Doing so you could already reduce the numbers of variables you use.

I do not understand what you mean by "easier to code", but if you mean that you seek a way to more easily re-use this code, you could either make a static method that would display a cross with specific parameters or an object with a display function.

Here is an exemple of a Cross object:

public class Cross {

    private int sectionSize;

    public Cross(int sectionSize) {
        this.sectionSize = sectionSize;
    }

    public void display() {
        final int height = sectionSize * 3;
        final char character = '*';
        //The iterators
        int i, j;

        //This loop controls the line
        for (i = 0; i &lt; height; i++) {
            //Check wether or not to add spaces
            if (i &lt; sectionSize || i &gt; sectionSize * 2) {
                //Add spaces
                for (j = 0; j &lt; sectionSize; j++)
                    System.out.print(" ");
                //Add the characters
                for (j = 0; j &lt; sectionSize; j++)
                    System.out.print(character);
            }
            else
                for (j = 0; j &lt; height; j++)
                    System.out.print(character);
            System.out.println();
        }
    }
}


Or in the format of a static method (which is actually the display method of the last object without the comments):

public static void drawCross(int sectionSize, char character) {
    final int height = sectionSize * 3;
    int i, j;

    for (i = 0; i &lt; height; i++) {
        if (i &lt; sectionSize || i &gt; sectionSize * 2) {
            for (j = 0; j &lt; sectionSize; j++)
                System.out.print(" ");
            for (j = 0; j &lt; sectionSize; j++)
                System.out.print(character);
        }
        else
            for (j = 0; j &lt; height; j++)
                System.out.print(character);
        System.out.println();
    }
}


Here is how you would use either of these solutions:

public static void main(String [] args) {
    final int sectionSize = 5;

    //Use of the Object
    Cross cross = new Cross(sectionSize);
    cross.display();

    //Use of the static method
    Cross.drawCross(sectionSize, '*');
}


Now, if it were not for the necessity of using For loops, I would have replaced the loop that adds the space with a simpler:

System.out.printf(("%," + sectionSize + "s"), "");


and then I would have added the characters of the cross in a loop.
I hope this helps you.