- To print full blank square pattern using *
User Input: 3
Output:
* * * * * * * *
import java.util.Scanner;
public class Pattern {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("Enter number of rows : ");
int rows;
rows=userInput.nextInt();
for(int i=1; i<=rows; i++) {
for(int j=1; j<=rows; j++) {
if(i==1||i==rows||j==1||j==rows)System.out.print("* ");
else System.out.print(" ");
}
System.out.print("\n");
}
}
}
Enter number of rows: 6 * * * * * * * * * * * * * * * * * * * *Program
Main Logic :
for(int i=1; i<=rows; i++) {
for(int j=1; j<=rows; j++) {
if(i==1||i==rows||j==1||j==rows)System.out.print("* ");
else System.out.print(" ");
}
System.out.print("\n");
}
You can print any thing in this pattern, just replace your value with *