ok now what i want out of this program is to be able to ask the user how large the height and width of the drawing should be. (i seem to have this down ok or at least i think i do)
i also want to be able to have it so that the program should accept only odd numbers, when the user asks for an even number, ask again. (i cannot seem to figure out this portion too well)
also i want draw a square of the desired size utilizing the “*” character for the boundaries of the box, a “@” for the very center of the box, and “\” for the remaining parts(i cant figure out where to place the portion of the loop for the @)
this is what i have so far for the code.....its messy and all but ah well
the only import i want in this is the java.swing so no scanner or array or anything
i dont even want the if...else in there but i dont know how to do it with just the for loop

import javax.swing.JOptionPane;

public class ex7 {
    public static void main(String[] args) {
    int shapeWidth = (Integer.parseInt(JOptionPane.showInputDialog("Enter the value for the width of your shape")));
    int shapeheight = (Integer.parseInt(JOptionPane.showInputDialog("Enter the value for the height of your shape")));

    for (int i = 1; i <= shapeheight; i++) {

        for (int j = 1; j <= shapeWidth; j++) {
        if (i == 1 || i == shapeheight)
            System.out.print('*');
        else if (j == 1 || j == shapeWidth)
            System.out.print('*');
        else
            System.out.print('/');
        }
        System.out.println();

    }
    }
}

You have two separate problems. Approach them separately and independently:

  1. Get good input from user.
  2. Draw rectangle based on that input.

Part 1 - You must ask the user for input. You must check that input to see if it meets your requirements. If not, you should tell the user what he did wrong and give him a chance to enter it again. Hence the code where you ask for input must be inside some sort of loop, either a for-loop or a while loop. How many times will the user enter bad data? You have no idea, so the loop should be a while loop, not a for-loop.

Part 2 - Once you have good data, you need to draw the rectangle. There's more than one way of doing it. You can break it up into five stages.

  1. Print the top line.
  2. Print the lines that are not the top line, but are above the center line.
  3. Print the center line.
  4. Print the lines that are not the bottom line, but are below the center line.
  5. Print the bottom line.

Depending on how many lines there are, you may not need to do all of them. If the height is less than 5, you will not do all five steps. Do the steps that you need to do in order.

Within steps 2, 3, and 4, you'll be displaying different characters, so split it into sub-steps.

Breaking the larger task into these smaller tasks will make things more manageable.

commented: Good adive. Many students fail to see the pro's of breaking down problems into smaller managable ones. +12
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.