Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void createArray(int rowsCount, int columnsCount) {
- int rowStep = 0;
- for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++) {
- if (Math.pow(2, rowStep + 1) <= rowIndex) {
- rowStep++;
- }
- int columnStep = 0;
- for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++) {
- if (Math.pow(2, columnStep + 1) <= columnIndex) {
- columnStep++;
- }
- int value = 0;
- int maxStep = Math.max(rowStep, columnStep);
- for (int stepIndex = 0; stepIndex <= maxStep; stepIndex++) {
- int stepPow = (int) Math.pow(2, stepIndex);
- int checkRow = (rowIndex / stepPow) % 2;
- int checkColumn = (columnIndex / stepPow) % 2;
- if (checkRow != checkColumn) {
- value += stepPow;
- }
- }
- System.out.print(value + "\t");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment