0% found this document useful (0 votes)
17 views4 pages

SIGMAxJINWOO's Square Matrix

The document contains a Java program that prompts the user to enter the order of a matrix (between 4 and 9) and three characters. It then constructs a square matrix where the corners are filled with the first character, the boundaries with the second character, and the inner cells with the third character. Finally, the program prints the constructed matrix to the console.

Uploaded by

karmakarrit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

SIGMAxJINWOO's Square Matrix

The document contains a Java program that prompts the user to enter the order of a matrix (between 4 and 9) and three characters. It then constructs a square matrix where the corners are filled with the first character, the boundaries with the second character, and the inner cells with the third character. Finally, the program prints the constructed matrix to the console.

Uploaded by

karmakarrit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME – RIT KARMAKAR

CLASS – XII SECTION – HUMANITIES/ARTS

UID-7768758 INDEX NO.- 096

SUBJECT-COMPUTER SCIENCE PRACTICAL PAPER 2

DATE-17/01/25

PROGRAM

import java.util.*;

class Mat

public static void main()

Scanner in = new Scanner(System.in);

int n,i,j;

while(true)

System.out.println("Enter the order of the matrix(4 - 9):");

n = in.nextInt();

if(n >= 4 && n <= 9)

break;

else

System.out.println("Invalid Number. Please enter a number between 4 - 9:");

char c1,c2,c3;

System.out.println("Enter the first character:");


c1 = in.next().charAt(0);

System.out.println("Enter the second character:");

c2 = in.next().charAt(0);

System.out.println("Enter the third character:");

c3 = in.next().charAt(0);

char m[][] = new char[n][n];

//fill the corners with character 1

m[0][0] = c1;

m[0][n-1] = c1;

m[n-1][0] = c1;

m[n-1][n-1] = c1;

//fill the boundaries(except the corners) with character 2

for(i = 1; i < n-1; i++)

m[0][i] = c2;

m[n-1][i] = c2;

m[i][0] = c2;

m[i][n-1] = c2;

//fill the non-boundaries with character 3

for(i = 1; i < n-1; i++)

{
for(j = 1; j < n-1; j++)

m[i][j] = c3;

//Print the matrix

for(i = 0; i < n; i++)

for(j = 0; j < n; j++)

System.out.print(m[i][j] + "");

System.out.println();

OUTPUT

You might also like