Display Shapes with Asterisks in Java | Java Practice Question – 4

Write an application that display a box using asterisks ( * ) as follows- 
https://youtu.be/syjU7vzrEiU

Begins the declaration of class DisplayShapesWithAsterisks. and remember, the file name for this public class must be DisplayShapesWithAsterisks.java

public class DisplayShapesWithAsterisks

Note – Don’t forget an opening and closing braces.

Create the main method of java. that is available on every java program

public static void main(String[] args)

Initialize the loop with these rules

public class DisplayShapesWithAsterisks{
  public static void main(String[] args){
    for (int i = 1; i <= 9 ; i++){
      for (int j = 1; j <= 9; j++){
        if(i == 1 || j == 1 || i == 9 || j == 9)
          system.out.print("*");
        else
          system.out.print(" ");
      }
      System.out.pritln();
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *