gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Please write a program PrintStarsSquare.java that prints a square of * and takes edge…
- User
Please write a program PrintStarsSquare.java that prints a square of * and takes edge length as input:
- Assistant
Here's a solution in Java that prints a square of asterisks based on the given edge length:
javaimport java.util.Scanner; public class PrintStarsSquare { public static void main(String[] args) { // Read the edge length from user input Scanner scanner = new Scanner(System.in); System.out.println("Enter the edge length: "); int edgeLength = scanner.nextInt(); scanner.close(); // Print the square of asterisks for (int i = 0; i < edgeLength; i++) { for (int j = 0; j < edgeLength; j++) { System.out.print("*"); } System.out.println(); } } }To run this program, compile it using the
javaccommand followed by the file name (PrintStarsSquare.java). Then, execute it using thejavacommand followed by the class name (). The program will prompt you to enter the edge length, and once you provide the input, it will print the square of asterisks.