Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.PrintStream;
- import java.util.Scanner;
- public class test {
- public static Scanner in = new Scanner(System.in);
- public static PrintStream out = System.out;
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt(), m = in.nextInt();
- for (int i = 0; i < n; i++) {
- if (i % 2 == 0) {
- for (int j = 0; j < m; j++) {
- System.out.print(m * i + j + 1 + " ");
- }
- } else {
- for (int j = m - 1; j >= 0; j--) {
- System.out.print(m * i + j + 1 + " ");
- }
- }
- out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement