I am trying to recreate sierpinski carpet in Java using recursion.
Say I have the following:
static int size = 9;
static char[][] board = new char[size][size];
And I wanted to remove the middle 3x3 sub array, how would I go about doing this using only recursion?
You cannot remove a sub array from an array declared like you are declaring it. But you can absolutely copy it. I have added comments in the solution below for you to fill in.
public char[][] copySubArray(char[][] orig, int colWidth, int rowHeight, int start_x, int start_y) {
//do bounds testing on orig based on starting values and width/height
char[][] copy = new char[colWidth][rowHeight];
//copy values from orig to copy
return copy;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.