I have a question and I almost completed this. However, have a simple problem which I can't solve.
Design and implement a program that uses for loops to print the following rectangular pattern with a user specified width, height and wall thickness.
Enter width, height & thickness: 5 6 2
*****
*****
** **
** **
*****
*****
Enter width, height & thickness: 10 10 3
**********
**********
**********
*** ***
*** ***
*** ***
*** ***
**********
**********
**********
This is my code:
int row;
int column;
row=0;
column=0;
int height;
int width;
int thickness;
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter the width: ");
width=keyboard.nextInt();
System.out.print("Please enter the height: ");
height=keyboard.nextInt();
System.out.print("Please enter the thickness: ");
thickness=keyboard.nextInt();
for(row = 0; row < height; row++)
{
for(column = 0; column < width; column++)
{
if(row < thickness)
{
System.out.print("*"); //prints top part
}
else if(row >= (height - thickness))
{
System.out.print("*"); // prints bottom part
}
else if( column < thickness )
{
System.out.print("*");
if( column< thickness )
{
System.out.print("*");
}
}
}
System.out.println();
}
}
}
And I get
**********
**********
**********
****** //
****** //
****** // In these lines I don't know how to put spaces
****** // between asterisks. Can you help me?
**********
**********
**********