Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Life.java
- * Mark Schmele
- * Creates a matrix of boolean values to represent life in an area of a grid
- * 9/2/2012
- */
- import java.util.*;
- public class Life {
- public static void main(String args[]){
- Scanner console = new Scanner(System.in);
- int rows = console.nextInt();
- int columns = console.nextInt();
- long seed = console.nextLong();
- if(rows <= 0 || columns <= 0){
- System.out.println("Please use positive numbers.");
- }else{
- makeMatrix(rows, columns, seed);
- }
- }
- // declares the matrix and fills it with booleans, then prints it
- public static void makeMatrix(int rows, int columns, long seed){
- //border
- boolean [][] liveGrid = new boolean[rows][columns];
- for(int i = 0; i <= liveGrid.length - 1; i++){
- for(int j = 0; j <= liveGrid[0].length - 1; j++){
- liveGrid[i][j] = false;
- }
- }
- //insides
- for(int ii = 1; ii <= liveGrid.length - 2; ii++){
- for(int jj = 1; jj <= liveGrid[1].length - 2; jj++){
- liveGrid[ii][jj] = isLive();
- }
- }
- for(int i = 0; i <= liveGrid.length - 1; i++){
- for(int j = 0; j<= liveGrid[0].length - 1; j++){
- if(liveGrid [i][j]){
- System.out.print("# ");
- }else{
- System.out.print("- ");
- }
- }
- System.out.println();
- }
- }
- // returns a random boolean value
- public static boolean isLive(){
- Random rand = new Random();
- return rand.nextBoolean();
- }
- }
Add Comment
Please, Sign In to add comment