从方法创建和返回数组 [英] creating and returning an array from a method

查看:110
本文介绍了从方法创建和返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个检查3x3网格中心项周围的方法,如果8个相邻位置的内容包含我要检查的内容我想在长度为7的数组上标记该方块1。

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;
}

这篇关于从方法创建和返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆