I need a code to help me print a square of stars with an Integer input (in this case the number is 5) the square must be empty on the inside.
for example:
Looking for this output
* * * * *
* *
* *
* *
* * * * *
what I get
* * * *
*
*
*
* * * *
I am missing my right side of the square.
MY code:
System.out.print("Please enter a number: ");
side = input.nextInt();
for (int i = 0; i < side - 1; i++) {
System.out.print("* ");
}
for (int i = 0; i < side; i++) {
System.out.println("*");
}
for (int i = 0; i < side; i++) {
System.out.print("* ");
}
}
input
5
output
* * * *
*
*
*
* * * *
You can do this with a nested for loop.
Print a
*
if it is either first row/column or last row/column; otherwise print two spaces.