Trouble with multidimensional arraysCreate ArrayList from arrayHow do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?Why is processing a sorted array faster than processing an unsorted array?Toad pattern in game of lifeHow to count live neighbours of a cell in Conway's Game of Life?Main class in Game Of Life isn't workingDesigning a multi-thread matrix in JavaJava: How to implement Conway's Game of Life?How do you kill off the live cells and revive the live cells without messing up the counter? Logic error in Conway's Game of Life
Possibility to correct pitch from digital versions of records with the hole not centered
How to say "is going" in Russian in "this game is going to perish"
Was it ever illegal to name a pig "Napoleon" in France?
Array or vector? Two dimensional array or matrix?
Why does the Misal rico de Cisneros uses the word "Qiſſa", and what is it supposed to mean? Why not "Miſſa" (Missa)?
What's the difference between a type and a kind?
What purpose does mercury dichloride have in fireworks?
Attach a visible light telescope to the outside of the ISS
This LM317 diagram doesn't make any sense to me
Why do airports remove/realign runways?
What are some bad ways to subvert tropes?
What is the Taylor series of a square root?
How was the website able to tell my credit card was wrong before it processed it?
When is one 'Ready' to make Original Contributions to Mathematics?
How to have a filled pattern
Who goes first? Person disembarking bus or the bicycle?
E12 LED light bulb flickers when OFF in candelabra
How to understand flavors and when to use combination of them?
Is this car delivery via Ebay Motors on Craigslist a scam?
What is this burst transmission sequence across the entire band?
Does anyone have a method of differentiating informative comments from commented out code?
How many Jimmys can fit?
I don't want to be introduced as a "Minority Novelist"
Which is a better conductor, a very thick rubber wire or a very thin copper wire?
Trouble with multidimensional arrays
Create ArrayList from arrayHow do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?Why is processing a sorted array faster than processing an unsorted array?Toad pattern in game of lifeHow to count live neighbours of a cell in Conway's Game of Life?Main class in Game Of Life isn't workingDesigning a multi-thread matrix in JavaJava: How to implement Conway's Game of Life?How do you kill off the live cells and revive the live cells without messing up the counter? Logic error in Conway's Game of Life
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
For my homework, I need to represents cells in a universe where ' * ' indicates a live cell and an empty space (' ') a dead cell. The following rules are used to determine the status of a particular cell in the next generations:
- Any live cell with fewer than two live neighbors dies, as if caused by under population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if caused by overpopulation.
- Any dead cell with exactly three live neighbors becomes a live cell, as if caused by reproduction.
For example, considering the following arrays:
int[][] beehive = 0,0,0,0,0,0, 0,0,1,1,0,0, 0,1,0,0,1,0,
0,0,1,1,0,0, 0,0,0,0,0,0;
int[][] toad = 0,0,0,0,0,0, 0,0,1,1,1,0, 0,1,1,1,0,0, 0,0,0,0,0,0;
getNextGenCell(beehive, 1, 3) returns 1, while getNextGenCell(beehive, 3, 1)
returns 0.
getNextGenCell(toad, 0, 3) returns 1, while getNextGenCell(toad, 2, 3)
returns 0.
I am confused on how to proceed with this code. Any suggestion?
My code has to have the following header where int x represents a sub-array and int y represents an element inside that sub-array. The code returns 1 if the cell is alive in the next generation or 0, otherwise.
// A method that gets the cell from the next generation
public static int getNextGenCell(int[][] validUniverse, int x, int y)
java multidimensional-array
|
show 2 more comments
For my homework, I need to represents cells in a universe where ' * ' indicates a live cell and an empty space (' ') a dead cell. The following rules are used to determine the status of a particular cell in the next generations:
- Any live cell with fewer than two live neighbors dies, as if caused by under population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if caused by overpopulation.
- Any dead cell with exactly three live neighbors becomes a live cell, as if caused by reproduction.
For example, considering the following arrays:
int[][] beehive = 0,0,0,0,0,0, 0,0,1,1,0,0, 0,1,0,0,1,0,
0,0,1,1,0,0, 0,0,0,0,0,0;
int[][] toad = 0,0,0,0,0,0, 0,0,1,1,1,0, 0,1,1,1,0,0, 0,0,0,0,0,0;
getNextGenCell(beehive, 1, 3) returns 1, while getNextGenCell(beehive, 3, 1)
returns 0.
getNextGenCell(toad, 0, 3) returns 1, while getNextGenCell(toad, 2, 3)
returns 0.
I am confused on how to proceed with this code. Any suggestion?
My code has to have the following header where int x represents a sub-array and int y represents an element inside that sub-array. The code returns 1 if the cell is alive in the next generation or 0, otherwise.
// A method that gets the cell from the next generation
public static int getNextGenCell(int[][] validUniverse, int x, int y)
java multidimensional-array
1
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39
|
show 2 more comments
For my homework, I need to represents cells in a universe where ' * ' indicates a live cell and an empty space (' ') a dead cell. The following rules are used to determine the status of a particular cell in the next generations:
- Any live cell with fewer than two live neighbors dies, as if caused by under population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if caused by overpopulation.
- Any dead cell with exactly three live neighbors becomes a live cell, as if caused by reproduction.
For example, considering the following arrays:
int[][] beehive = 0,0,0,0,0,0, 0,0,1,1,0,0, 0,1,0,0,1,0,
0,0,1,1,0,0, 0,0,0,0,0,0;
int[][] toad = 0,0,0,0,0,0, 0,0,1,1,1,0, 0,1,1,1,0,0, 0,0,0,0,0,0;
getNextGenCell(beehive, 1, 3) returns 1, while getNextGenCell(beehive, 3, 1)
returns 0.
getNextGenCell(toad, 0, 3) returns 1, while getNextGenCell(toad, 2, 3)
returns 0.
I am confused on how to proceed with this code. Any suggestion?
My code has to have the following header where int x represents a sub-array and int y represents an element inside that sub-array. The code returns 1 if the cell is alive in the next generation or 0, otherwise.
// A method that gets the cell from the next generation
public static int getNextGenCell(int[][] validUniverse, int x, int y)
java multidimensional-array
For my homework, I need to represents cells in a universe where ' * ' indicates a live cell and an empty space (' ') a dead cell. The following rules are used to determine the status of a particular cell in the next generations:
- Any live cell with fewer than two live neighbors dies, as if caused by under population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if caused by overpopulation.
- Any dead cell with exactly three live neighbors becomes a live cell, as if caused by reproduction.
For example, considering the following arrays:
int[][] beehive = 0,0,0,0,0,0, 0,0,1,1,0,0, 0,1,0,0,1,0,
0,0,1,1,0,0, 0,0,0,0,0,0;
int[][] toad = 0,0,0,0,0,0, 0,0,1,1,1,0, 0,1,1,1,0,0, 0,0,0,0,0,0;
getNextGenCell(beehive, 1, 3) returns 1, while getNextGenCell(beehive, 3, 1)
returns 0.
getNextGenCell(toad, 0, 3) returns 1, while getNextGenCell(toad, 2, 3)
returns 0.
I am confused on how to proceed with this code. Any suggestion?
My code has to have the following header where int x represents a sub-array and int y represents an element inside that sub-array. The code returns 1 if the cell is alive in the next generation or 0, otherwise.
// A method that gets the cell from the next generation
public static int getNextGenCell(int[][] validUniverse, int x, int y)
java multidimensional-array
java multidimensional-array
edited Mar 25 at 21:34
Elizabeth
asked Mar 25 at 21:31
ElizabethElizabeth
165 bronze badges
165 bronze badges
1
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39
|
show 2 more comments
1
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39
1
1
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39
|
show 2 more comments
1 Answer
1
active
oldest
votes
You first must determine how you want the logic of your program to flow. In this case, you know there are 8 different cases when traversing the 2D array. These include:
- The upper left-hand corner
- The upper right-hand corner
- The rest of the first row
- The lower left-hand corner
- The lower right-hand corner
- The rest of the last row
- The left and right-hand sides of the array
- The rest of the array
You will need if statements for each of these cases. The following is an an example of the code for "the rest of the array" case:
if(x!=0&&y!=0&&x!=bees.length-1&&y!=bees[x].length-1&&bees[x][y+1]==1||bees[x][y-1]==1||bees[x+1][y]==1||bees[x-1][y]==1)
Now just finish the other 7 cases, count the amount of "alive" or "dead" cells and modify the array accordingly. Let me know if you have any questions.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346699%2ftrouble-with-multidimensional-arrays%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You first must determine how you want the logic of your program to flow. In this case, you know there are 8 different cases when traversing the 2D array. These include:
- The upper left-hand corner
- The upper right-hand corner
- The rest of the first row
- The lower left-hand corner
- The lower right-hand corner
- The rest of the last row
- The left and right-hand sides of the array
- The rest of the array
You will need if statements for each of these cases. The following is an an example of the code for "the rest of the array" case:
if(x!=0&&y!=0&&x!=bees.length-1&&y!=bees[x].length-1&&bees[x][y+1]==1||bees[x][y-1]==1||bees[x+1][y]==1||bees[x-1][y]==1)
Now just finish the other 7 cases, count the amount of "alive" or "dead" cells and modify the array accordingly. Let me know if you have any questions.
add a comment |
You first must determine how you want the logic of your program to flow. In this case, you know there are 8 different cases when traversing the 2D array. These include:
- The upper left-hand corner
- The upper right-hand corner
- The rest of the first row
- The lower left-hand corner
- The lower right-hand corner
- The rest of the last row
- The left and right-hand sides of the array
- The rest of the array
You will need if statements for each of these cases. The following is an an example of the code for "the rest of the array" case:
if(x!=0&&y!=0&&x!=bees.length-1&&y!=bees[x].length-1&&bees[x][y+1]==1||bees[x][y-1]==1||bees[x+1][y]==1||bees[x-1][y]==1)
Now just finish the other 7 cases, count the amount of "alive" or "dead" cells and modify the array accordingly. Let me know if you have any questions.
add a comment |
You first must determine how you want the logic of your program to flow. In this case, you know there are 8 different cases when traversing the 2D array. These include:
- The upper left-hand corner
- The upper right-hand corner
- The rest of the first row
- The lower left-hand corner
- The lower right-hand corner
- The rest of the last row
- The left and right-hand sides of the array
- The rest of the array
You will need if statements for each of these cases. The following is an an example of the code for "the rest of the array" case:
if(x!=0&&y!=0&&x!=bees.length-1&&y!=bees[x].length-1&&bees[x][y+1]==1||bees[x][y-1]==1||bees[x+1][y]==1||bees[x-1][y]==1)
Now just finish the other 7 cases, count the amount of "alive" or "dead" cells and modify the array accordingly. Let me know if you have any questions.
You first must determine how you want the logic of your program to flow. In this case, you know there are 8 different cases when traversing the 2D array. These include:
- The upper left-hand corner
- The upper right-hand corner
- The rest of the first row
- The lower left-hand corner
- The lower right-hand corner
- The rest of the last row
- The left and right-hand sides of the array
- The rest of the array
You will need if statements for each of these cases. The following is an an example of the code for "the rest of the array" case:
if(x!=0&&y!=0&&x!=bees.length-1&&y!=bees[x].length-1&&bees[x][y+1]==1||bees[x][y-1]==1||bees[x+1][y]==1||bees[x-1][y]==1)
Now just finish the other 7 cases, count the amount of "alive" or "dead" cells and modify the array accordingly. Let me know if you have any questions.
answered Mar 27 at 3:48
TomTom
363 bronze badges
363 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346699%2ftrouble-with-multidimensional-arrays%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
People around here can be a bit "picky" when it comes to answering questions. You do a good job of explaining your homework assignment, but you need to explain what it is SPECIFICALLY that confuses you about how to proceed. The instructions you've provided seem clear, so what part about them don't you get? It also helps to tell people what you've tried and why it hasn't given you the result you wanted or expected. Best of luck!
– Dan Forbes
Mar 25 at 21:33
@DanForbes I'm confused on how to start writing the code. I am looking for any suggestion or tip on how to proceed.
– Elizabeth
Mar 25 at 21:36
For a given x, y coordinate, how would you determine the neighbors? Work out the algorithm first, then try to write the code to match.
– KevinO
Mar 25 at 21:36
@KevinO I was thinking of doing nested for loops, but it seems so inefficient.
– Elizabeth
Mar 25 at 21:37
@Elizabeth - I would suggest you visit office hours and work with a TA or your professor for basic questions like that.
– Dan Forbes
Mar 25 at 21:39