Topic: 关于2维数组做参数传递的问题 |
Print this page |
1.关于2维数组做参数传递的问题 | Copy to clipboard |
Posted by: zmzbs123 Posted on: 2005-11-06 20:05 public int blessMe(Chain a[][];int x;int y) { return a[x][y].getColor(); } Chain是我定义的一个类 比如我想把a[x][y]的值传到方法blessMe中进行处理,可是编译器老是 报错,不知道什么原因; 另外,Chain[][] a;与Chain a[][] 都是合法的,不知道有什么区别,请高手指点 |
2.Re:关于2维数组做参数传递的问题 [Re: zmzbs123] | Copy to clipboard |
Posted by: wallacer Posted on: 2005-11-07 18:02 public class A { public int fun(B[][] b, int x, int y) { return b[x][y].getN(); } public static void main(String[] args) { A a = new A(); B[][] b = new B[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) b[i][j] = new B(i + j); } int x = a.fun(b, 1, 1); System.out.println("" + x); } } class B { private int n = 0; public B(int m) { n = m; } public int getN() { return n; } } 看看这个例子你就能明白了!呵呵 |
3.Re:关于2维数组做参数传递的问题 [Re: zmzbs123] | Copy to clipboard |
Posted by: zmzbs123 Posted on: 2005-11-09 00:15 谢谢楼上的高手指点,受益匪浅啊 |
4.Re:关于2维数组做参数传递的问题 [Re: zmzbs123] | Copy to clipboard |
Posted by: zhouxha Posted on: 2005-12-21 08:56 数组没有初始化 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |