Latest :

Square Star Pattern Program In Java – Patterns

Java program to print square star pattern program. We have written the below print/draw square asterisk/star pattern program in four different ways with sample example and output, check it out. At the end of the program, we added compiler such that you can execute the below codes:

  • Print Square Star Pattern – Using For Loop
  • Print – Using While Loop
  • print – Using Do While Loop

Using Standard Java Program


Using For Loop

1) Read n value and store it into the variable n

2) The outer loop iterates n times with the structure for(i=0;i<n;i++).

3) The inner loop iterates n times with the structure for(j=0;j<n;j++).

4) The inner loop checks the condition j<n

5) Prints character for n rows and n columns.


Using While Loop

1) The outer while loop executes iterates until the condition i++<n is false.

2) The inner loop will display the character until the condition j++<n is false for every i value.


Using Do-While Loop

1) The outer do-while loop iterates until the condition ++i<n is false.

2) The inner loop prints the character until the condition ++j<n is false for each i value.


More Programs:


Check Also

Java Program to Add Two Matrices – 4 Ways | Programs

Java program to add two matrices – The following Java Code will let you know ...