Program:: Computer Science Practical Revision Exam Name: D. Hari Varshan Class: Xii-B ROLL: 09
Program:: 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;
}
}
OUTPUT: