This program will be used to print a star pattern that will generate a rectangle.
Example:
******* * * * * * * * * * * *******
public class Pattern9 { public static void main(String[] args) { int number = 7; for (int i = 0; i < number; i++) { if (i == 0 || i == 6) { for (int j = 0; j < number; j++) { System.out.print("*"); } System.out.println(); } if (i >= 1 && i <= 5) { for (int j = 0; j < number; j++) { if (j == 0 || j == 6) { System.out.print("*"); } else if (j >= 1 && j <= 5) { System.out.print(" "); } } System.out.println(); } } } }
Output
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program to print rentable using stars in java
Output