开发者

creating and returning an array from a method

开发者 https://www.devze.com 2022-12-25 08:12 出处:网络
i currently have a method that checks what is around the centre item in a 3x3 grid, if what is in the 8 adjacent positions is containing what i am checking for i want to mark that square on an array w

i currently have a method that checks what is around the centre item in a 3x3 grid, if what is in the 8 adjacent positions is containing what i am checking for i want to mark that square on an array with length 7 as being 1.

to do this i need to create and return an array 开发者_高级运维in my method, is it possible to do this?


Not sure what is the problem. You mean this?

public int[] myMethod() {
 //...
 int[] res = new int[7];
 //... set values ...
 return res;
}


Declare the return type to be two dimensional array (int[][]), create the array in your method and return that.

public int[][] getArray() {
  int[][] myArray = new int[3][3];
  // Populate array
  return myArray;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号