forked from twowaits/make-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2ndOct_DPrasoon.java
47 lines (43 loc) · 887 Bytes
/
2ndOct_DPrasoon.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
40
41
42
43
44
45
46
47
//Zigzag Pattern
import java.util.Scanner;
class ZigZag
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
System.out.print("Enter number of columns: ");
int column = sc.nextInt();
int[][] arr = new int[rows][column];
int k = 0;
boolean var = true;
for (int j = 1; j <= column; j++)
{
arr[k][j - 1] = j;
if (k == 0)
{
var = false;
}
if (k == (rows - 1))
{
var = true;
}
if (var)
--k;
else
++k;
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < column; j++)
{
if (arr[i][j] != 0)
System.out.print(arr[i][j]);
else
System.out.print(" ");
}
System.out.println();
}
}
}