- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnake.java.bak
More file actions
Latest commit
42 lines (39 loc) · 500 Bytes
/
Copy pathSnake.java.bak
File metadata and controls
42 lines (39 loc) · 500 Bytes
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
class Snake
{
public static void main(String[] args)
{
int n = 5;
int k = 1;
for (int i=0;i<n ;i++ )
{
int l=0;
if (i%2==0)
{
k=k+i;
}
else
{
l = k+i;
}
for (int j=0;j<n ;j++ )
{
if(i>=j)
{
if(i%2==0)
{
System.out.print(k++);
}
else
{
System.out.print(l--);
}
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}