Repository navigation
Expand file tree
/
Copy pathpattern.java
More file actions
58 lines (45 loc) · 1.44 KB
/
Copy pathpattern.java
File metadata and controls
58 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
class pattern
{
public static void main (String args[])
{
Scanner sc=new Scanner (System.in);
System.out.println("input");
int n=sc.nextInt();
int m=sc.nextInt();
if((n>3&&n<10)&&(n==m))
{
char a[][]=new char[n][n];
System.out.println("enter first character");
char first=sc.next().charAt(0);
System.out.println("enter second char");
char second=sc.next().charAt(0);
System.out.println("enter third character");
char third=sc.next().charAt(0);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if((i==0||i==n-1)&&(j==n-1||j==0))
a[i][j]=first;
else if((i>0&&i<n-1)&&(j>0&&j<n-1))
a[i][j]=third;
else
a[i][j]=second;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.println(a[i][j]+" ");
}
}
System.out.println();
}
else
{
System.out.print("enter valid square matrix");
}
}
}