Advertisement
Guest User

dcjsc

a guest
Oct 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. import java.io.PrintStream;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class test {
  6.  
  7.  
  8.     public static Scanner in = new Scanner(System.in);
  9.     public static PrintStream out = System.out;
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner in = new Scanner(System.in);
  13.         int n = in.nextInt(), m = in.nextInt();
  14.         for (int i = 0; i < n; i++) {
  15.             if (i % 2 == 0) {
  16.                 for (int j = 0; j < m; j++) {
  17.  
  18.                     System.out.print(m * i + j + 1 + " ");
  19.                 }
  20.             } else {
  21.                 for (int j = m - 1; j >= 0; j--) {
  22.                     System.out.print(m * i + j + 1 + " ");
  23.                 }
  24.             }
  25.             out.println();
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement