//college work
Hello, I am trying to print a square by using loops, it also require the user to input the height and width. The Output should look like this
.... . . ....
any help would be apprciated
import java.util.Scanner;
public class Ex1 {
public static void main(String[] args) {
Scanner input = new Scanner(System. in );
System.out.print("Please enter the height of the box: ");
int x = input.nextInt();
System.out.println("Please enter a width for the box: ");
int y = input.nextInt();
drawbox(x, y);
}
static void drawbox(int x, int y) {
for (int j = 0; j < y; j++) {
System.out.println("*");
System.out.println();
for (int i = 0; i < x - 2; i++) {
System.out.print("*");
for (int z = 0; z < y - 2; z++) {
System.out.print(" ");
}
System.out.println("*");
for (int i = 0; j < y; j++) {
System.out.println("*");
}
}
}
}
}