0% found this document useful (0 votes)
39 views3 pages

Program:: Computer Science Practical Revision Exam Name: D. Hari Varshan Class: Xii-B ROLL: 09

This document contains a Java program to create a matrix with three different characters. The program takes the size of the matrix and three characters as input, and prints the matrix with the corner elements containing the first character, border elements containing the second character, and inner elements containing the third character.

Uploaded by

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

Program:: Computer Science Practical Revision Exam Name: D. Hari Varshan Class: Xii-B ROLL: 09

This document contains a Java program to create a matrix with three different characters. The program takes the size of the matrix and three characters as input, and prints the matrix with the corner elements containing the first character, border elements containing the second character, and inner elements containing the third character.

Uploaded by

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

COMPUTER SCIENCE

PRACTICAL REVISION EXAM


NAME: D. HARI VARSHAN
CLASS: XII-B
ROLL: 09

PROGRAM:

import java.util.*;
class matrix
{
void main(int n)
{
char c1=' ';
char c2=' ';
char c3=' ';
char A[][] = new char[n][n];
if(n>3&&n<10)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1st character");
c1= sc.next().charAt(0);
System.out.println("Enter 2nd character");
c2 = sc.next().charAt(0);
System.out.println("Enter 3rd character");
c3 = sc.next().charAt(0);
}
else
{
System.out.println("Size out of range");
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(((i==0&&j==0)==true)||((i==n-1&&j==n-1)==true)||((i==n-1&&j==0)==true)||
((i==0&&j==n-1)==true))
A[i][j] = c1;
else if((i>0&&i<n-1)==true&&(j>0&&j<n-1)==true)
A[i][j] = c3;
else
A[i][j] = c2;
}
}

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


{
for(int j=0; j<n; j++)
{
System.out.print(A[i][j]+"");
}
System.out.println();
}
}
}

OUTPUT:

You might also like