Created
November 1, 2011 18:42
-
-
Save ellbur/1331494 to your computer and use it in GitHub Desktop.
Pattern
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
| public class Pattern { | |
| public static void main(String[] args) { | |
| int width = 150; | |
| int height = 70; | |
| int[][] grid = new int[width][height]; | |
| grid[width/2][0] = 1; | |
| for (int f=1; f<height; f++) { | |
| for (int i=1; i<width-1; i++) { | |
| if (grid[i-1][f-1] == 1 && grid[i+1][f-1] == 0) { | |
| grid[i][f] = 1; | |
| } | |
| if (grid[i-1][f-1] == 0 && grid[i+1][f-1] == 1) { | |
| grid[i][f] = 1; | |
| } | |
| } | |
| } | |
| // Print it out | |
| for (int i=0; i<height; i++) { | |
| for (int j=0; j<width; j++) { | |
| if (grid[j][i] == 1) { | |
| System.out.print("X"); | |
| } | |
| else { | |
| System.out.print(" "); | |
| } | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment