-
Notifications
You must be signed in to change notification settings - Fork 0
/
510A-Fox and Snake.java
40 lines (38 loc) · 1.16 KB
/
510A-Fox and Snake.java
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
import java.util.Scanner;
public class foxandsnake {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
char arr[][]=new char[n][m];
for(int i = 0;i<arr.length;i++){
for(int j = 0;j<arr[0].length;j++){
arr[i][j] = '.';
}
}
for(int i = 0;i<arr.length;i++){
for(int j = 0;j<arr[0].length;j++){
if(i%2 == 0){
arr[i][j] = '#';
}
}
}
boolean flag = true;
for(int i = 1;i<arr.length;i+=2){
if(flag == true){
arr[i][arr[0].length-1] = '#';
flag = false;
}
else{
arr[i][0] = '#';
flag = true;
}
}
for(int ii = 0;ii<arr.length;ii++){
for(int jj = 0;jj<arr[ii].length;jj++){
System.out.print(arr[ii][jj]);
}
System.out.println();
}
}
}