Constructing a square

Hey guys new to forum cause am in need of some help.
I have to draw a 'square' in java whose outline is all *'s and whose interior is filled with the character . (dot).
I did some coding but I only reached the point of just creating a complete square. What do I have to change in order for the task to work?


class Main
{
public static void main( String args[] )
{
System.out.print("#Input Square Size ");
int symbol = BIO.getInt();
int l = 1;
while (l <= symbol)
{
int stars = 1;
while (stars <= symbol)
{
int i = 1;
stars = stars + 1;
System.out.print("*");
}
System.out.println();
l = l + 1;
}
}
}

Comments

  • Ok, alot of weird stuff in your code

    First, why not use for loops instead of while loops?
    All the variables you declare in your while loops are always reset to the value 1.
    [code]
    class Main
    {
    int i = 1;
    public static void main( String args[] )
    {
    System.out.print("#Input Square Size ");
    int symbol = BIO.getInt();//Implying this works
    for (int l=0; i<=symbol; i++)
    {
    for (int stars=0; stars <= symbol; stars++)
    {

    stars = stars + 1;//Could be written as stars++ or stars += 1
    System.out.print("*");
    }
    System.out.println();
    }
    }
    }
    [/code]
    This should do what you wanted it to do with that code.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion