Created
October 18, 2015 11:48
-
-
Save StrixG/5fb52637660812b4f8b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int[][] array = new int[in.nextInt()][in.nextInt()]; | |
for (int i = 0; i < array.length; i++) { | |
for (int j = 0; j < array[i].length; j++) { | |
if (i % 2 == 0) { | |
array[i][j] = i * array[i].length + j; | |
} else { | |
array[i][j] = (i + 1) * array[i].length - j - 1; | |
} | |
} | |
} | |
outArray(array); | |
} | |
static void outArray(int[][] array) { | |
for (int[] i : array) { | |
for (int value : i) { | |
System.out.printf("%3d", value); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment