22.7k views
1 vote
1. Write an application that prompts the user to enter the size of the side of a square, and then displays a hollow square of that size made of asterisks. Your program should work for squares of all side lengths between 1 and 20. This is a sample run of your program: Enter·the·size·of·the·asterisk·square·from·1-20:3↵ ***↵ *·*↵ ***↵

User Skrubber
by
3.3k points

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class HollowSquare

{

public static void main(String args[])

{

Scanner scan = new Scanner(System.in);

int size;

System.out.print("Enter the size : ");

size = scan.nextInt();

if(size>=1 && size<=20)

{

for(int i=0; i<size; i++)

{

for(int j=0; j<size; j++)

System.out.println();

}

}

else

System.out.println("Invalid size.");

}

}

User MarkGr
by
2.9k points