A Sensational Circular Matrix program
Circular Matrix program: solved Java program for ISC Class 12 Computer Science with complete BlueJ code, explanation and sample output.

Circular matrix: Write a Program in Java to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.
For example: if n = 4, then n*n = 16, hence the array will be filled as given below.
Input : m = 4, n = 4
Output : 1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
To learn more about how to take input using Buffered Reader in java watch the given video.
https://youtu.be/bTOMwnwpXqs
import java.io.*;
class Circular
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the length of the double dimensions-rows&columns-- ONLY ONE DIGIT IS TO BE ENTERED FOR BOTH");
int r=Integer.parseInt(br.readLine());
int c=r;
int Arr[][]=new int[r][c];
int k=1;
int c1=0;
int c2=c-1;
int r1=0;
int r2=r-1;
System.out.println("--------CIRCULAR MATRIX------------");
while(k<=(r*c))
{
for(int i=c1;i<=c2;i++)
{
Arr[r1][i]=k++;
}
for(int j=r1+1;j<=r2;j++)
{
Arr[j][c2]=k++;
}
for(int i=c2-1;i>=c1;i--)
{
Arr[r2][i]=k++;
}
for(int i=r2-1;i>=r1+1;i--)
{
Arr[i][c1]=k++;
}
c1 ++;
c2 --;
r1 ++;
r2 --;
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(Arr[i][j]+"\t");
}
System.out.println();
}
}
}Input: Enter the length of the double dimensions-rows&columns-- ONLY ONE DIGIT IS TO BE ENTERED FOR BOTH
4
Output:
--------CIRCULAR MATRIX------------
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
To learn more matrix programs click
A super Anticlockwise Circular Matrix program
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.