Java Program for Internal Varsity Number Square Pattern

Printing Internal Varsity Number Square Pattern:

In this problem we’re going to code a java program for printing basic internal varsity number square pattern. In this program we will take an integer input from user and store in the variable called “n” (in this case) and we’re running loop start from i=0 to i. Inside else part we will take another j for loop start from j=0 to j

Java Program for Internal Varsity Number Square Pattern


  1. Take number of rows as input from the user and save it in any variable (‘no’in this case).
  2. Run a loop ‘no’ number of times to iterate through the rows. From i=0 to i<no.  The loop should be structured as for( i=0 ; i<r ; i++).
  3. Inside this if condition use an id condition to print the top and bottom rows. if(i==0 || i==n).
  4. Inside this run a nested loop to iterate through the columns. From  j=1 to j<n. The loop should be structured as for (int j=1 ; j<n ; j++)
  5. Inside else part  take another for loop start with j=0 to j<n1 inside this for loop take if part if((j==0)||(j==2)) and print n1 and take else part and print System.out.print(i);
  6. After the main else part take line changement statement System.out.println();

Code in Java:

import java.util.Scanner;
public class Pattern1 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(;
		System.out.println("Enter no");
		int n = sc.nextInt();
		int n1=n-1;
		for (int i = 0; i<n ; i++) {
			if((i==0) || (i==n)) {
			for (int j=1 ; j<n ; j++)
			else {
				for (int j = 0; j<n1; j++) {

This code is contributed by Shubham Nigam (Prepinsta Placement Cell Student)

One comment on “Java Program for Internal Varsity Number Square Pattern”