File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .lang .*;
2+ import java .util .*;
3+ public class ZigZag {
4+ public static void main (String arg [])
5+ {
6+ int n ,k ;
7+ Scanner in = new Scanner (System .in );
8+ System .out .println ("Enter the number till you want to print the numbers" );
9+ n = in .nextInt ();
10+ System .out .println ("Enter the no. of rows" );
11+ k = in .nextInt ();
12+ String grid [][] = new String [k ][n ];
13+ for (int i =0 ;i <k ;i ++)
14+ {
15+ for (int j =0 ;j <n ;j ++)
16+ {
17+ grid [i ][j ]=" " ;
18+ }
19+ }
20+ for (int i =0 ;i <n ;i ++)
21+ {
22+ int m = k -1 ;
23+ int colm = m -Math .abs (i %(2 *m )-m );
24+ grid [colm ][i ]=Integer .toString (i +1 );
25+ }
26+ for (int i =0 ;i <k ;i ++)
27+ {
28+ for (int j =0 ;j <n ;j ++)
29+ {
30+ System .out .print (grid [i ][j ]);
31+ }
32+ System .out .println ();
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments