I'm having a lot of trouble understanding an assignment we were given today. It has to be written using only loops. I'm finding it a little hard to comprehend right now, so just a bit of guidance on where to start would be great.
I understand that the program would start at the top left so, everything would rely on nested loops.

The user is asked to enter:
An X,Y coordinate for the upper vertex
And the length of the pyramid

I.e. If a user entered 15,15 and 9

The result:

20+
|
|
|
|
15             *
|             ***
|            *****
|           *******
|          *********
10          *******
|            *****
|             ***
|              *
|
5
|
|
|
|
+----+----+----+----+----+----+----+---->
0

Thanks

So far, this is what I have:

import java.util.Scanner;

public class Assignment4
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int count, xCoord, yCoord, length;
        
        System.out.println("Please enter the X Coordinate: ");
        xCoord = input.nextInt();
        
        System.out.println("Please enter Y Coordinate: ");
        yCoord = input.nextInt();
        
        System.out.println("Please enter the length: ");
        length = input.nextInt();
        
        for (count = 20; count >= 0; count--)
        {
            System.out.println("|");
        }
        for (count = 1; count <= 40; count++)
        {
            System.out.print("+");
        }
    }
}

What I'm having trouble with is drawing the diamond. How do I tell the program where to start drawing?

By printing the right number of blank lines before it starts, then printing the right number of spaces before the *... on each line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.